Boquiron, Reymark E - QUEUE
Boquiron, Reymark E - QUEUE
Boquiron, Reymark E - QUEUE
Activity 3
Queue Implementation using array
and linked
list
}
else if(choice=="2"){
Delete();
}
else if(choice=="3"){
Display();
}
else if(choice=="4"){
cout<<"Exit"<<endl;
return 0;
}
else {
cout<<"Invalid choice"<<endl;}
}
} while(r!=4);
return 0;
}
Output
Queue Implementation using linked list
Activity 3
Sample code:
#include <iostream>
#include <stdlib.h>
#include <string>
using namespace std;
struct Node
{
int data, free;
Node *link;
};
bool isempty()
{
if(front == NULL && rear == NULL)
return true;
else
return false;
}
void dequeue ( )
{
if( isempty() )
cout<<"Queue is empty\n";
else
void showfront( )
{
if( isempty())
cout<<"Queue is empty\n";
else
cout<<"element at front is:"<<front->data;
}
void displayQueue()
{
if (isempty())
cout<<"Queue is empty\n";
else
{
Node *ptr = front;
while( ptr !=NULL)
{
cout<<ptr->data<<" ";
ptr= ptr->link;
}
}
}
int main()
{
string choice;
int r, f=1, value;
while( f == 1)
cout<<"\n-------------------------------------------\n";
cout<<" \nQueue Data Structure \n";
cout<<"-------------------------------------------\n";
cout<<" [1] Enqueue \n";
cout<<" [2] Dequeue \n";
cout<<" [3] Showfront\n";
cout<<" [4] Display Queue \n";
cout<<" [5] exit \n";
cout<<"-------------------------------------------\n";
{
cout<<"Pick your choice:";
cin>>choice;
if(choice=="1"){
cout<<"Enter Value:\n";
cin>>value;
enqueue(value);
else if (choice=="2") {
dequeue();
}
else if (choice=="3"){
showfront();
}
else if (choice=="4") {
displayQueue();
}
else {
f = 0;
}
}
}
return 0;
}
Sample output: