Mastering Queue Made Simple: Your Easy Guide to Data Structures !
Array implementation of queue code [C++] :
// Shyam Sunder Kanth// Insta : still_23.6_8// ?Queue array implementation#include<iostream>using namespace std;class Queue{public:int *arr;int size;int front;int rear;Queue(int size){this->size = size;arr = new int[size];front = -1;rear = -1;}void enque(int data){if(rear == size-1){cout<<"Queue overflow";return;}if(front == -1){front = rear = 0;arr[rear] = data;return;}rear++;arr[rear] = data;}void deque(){if(front == -1){cout<<"Queue Underflow.";return;}if(front == rear){front = rear = -1;return;}front++;}bool isEmpty(){if(front == -1){return true;}return false;}int frontEle(){if(front == -1){cout<<"Queue is empty.";return -1;}return arr[front];}int lastEle(){if(front == -1){cout<<"Queue is empty.";return -1;}return arr[rear];}int length(){if(front == -1){cout<<"Queue is empty.";return -1;}int cnt = 0;for(int i = front;i<=rear;i++){cnt++;}return cnt;}};int main(){Queue q(5);q.enque(4);q.enque(6);q.enque(9);q.deque();q.deque();cout<<q.isEmpty()<<endl;cout<<q.frontEle()<<endl;cout<<q.lastEle()<<endl;cout<<q.length()<<endl;return 0;}
In this video we’ll walk you through:
- Concept
- Operation
- Code
All codes are available at my GitHub account, check them out here:
https://github.com/shyamkanth/Placements
Check out other videos from DS Revealed playlist: https://www.youtube.com/playlist?list=PLNXqJgOsTCZOB60T9HDhMf_o8RXbNWgqS
Check out our channel here: https://www.youtube.com/@DevelopersByte
Find us at: https://shyamkanth.github.io/
Timestamps:
0:00 Intro
0:42 Concept
6:11 Enqueue operation
12:20 Dequeue operation
16:27 Front operation
16:48 Last operation
17:40 Length operation
20:06 isEmpty operation
20:40 Code
34:45 Outro
About our channel:
Our channel is about Revealing the secrets of Data Structure. We cover lots of cool stuff such as Codes, Concepts and Implementations.
Check out our channel here: https://www.youtube.com/@DevelopersByte
Don’t forget to subscribe!
Follow me on social media:
Get updates or reach out to Get updates on our Social Media Profiles!
GitHub: https://github.com/shyamkanth/
Instagram: https://instagram.com/still_23.6_8
Instagram personal: https://instagram.com/itz_sammmii
No comments:
Post a Comment