



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A practical guide to implementing stack and queue data structures using arrays in c++. It includes c++ code examples for both stack and queue, demonstrating essential operations such as push, pop, enqueue, and dequeue. The document also covers applications of stacks, such as backtracking, function calls, and string reversal, and applications of queues, such as cpu scheduling and synchronization. It is designed to help students understand and implement these fundamental data structures effectively. The document also includes assignment questions to test the understanding of the concepts.
Typology: Lecture notes
1 / 6
This page cannot be seen from the preview
Don't miss anything!




#include
#include
if (front==-1) front=0; rear++; Queue[rear]=item; } } int dequeue() { if(isEmpty()) { cout<<"Queue Underflow \n"; return - 1; } else { int item=Queue[front]; front++; return item; } } void traverse() { if(isEmpty()) cout<<"Queue is Empty \n"; else { for(int i=front;i<=rear;i++) cout<<Queue[i]<<" "; } cout<<endl; } void main() { int ch,item; front=rear=-1; cout<<"Enter Queue Size"; cin>>size; Queue=new int [size]; while(true) { cout<<"***************************************\n"; cout<<"1) Insert element to Queue \n"; cout<<"2) Delete element from Queue \n"; cout<<"3) Display all the elements of queue \n"; cout<<"4) Exit \n"; cout<<"***************************************\n"; cin>>ch; switch (ch) { case 1 : cout<<"Enter the item:"; cin>>item; enqueue(item); break; case 2 : cout<<dequeue()<<" Deleted from the Queue \n"; break;