Professional Documents
Culture Documents
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h> //For exit()
void main()
{
int top = -1;
int arr[max];
int choice;
do
{
cout << "\n\n\t\t MAIN MENU";
cout << "\n\t\t-----------\n";
cout << "\n\t 1. Push";
cout << "\n\t 2. Pop";
cout << "\n\t 3. Show";
cout << "\n\t 4. Exit";
cout << "\n\n\t Enter Choice : ";
switch(choice)
{
case 1 : {
push(arr, top);
break;
}
case 2 : {
pop(arr, top);
break;
}
case 3 : {
showstack(arr, top);
break;
}
default : {
cout << "\n\tInvalid Input";
getch();
exit(0);
}
}
clrscr();
}while(choice != 4);
getch();
}
LINEAR CIRCULAR QUEUE :
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<ctype.h>
#define max 20
char queue[max];
void main()
{
int choice;
char val;
char opt = 'Y';
rear = -1;
front = -1;
clrscr();
do
{
cout << "\n\t\t MAIN MENU";
cout << "\n\t\t-----------";
cout << "\n\t 1. Addition of Queue";
cout << "\n\t 2. Deletion of Queue";
cout << "\n\t 3. Traverse of Queue";
cout << "\n\t 4. Exit";
clrscr();
switch(choice)
{
case 1 : {
do
{
cout << "\n\t Enter the value to be added : ";
cin >> val;
add_q(queue, front, val, rear);
cout << "\n\n\t Add more elements (Y / N) : ";
cin >> opt;
}while(toupper(opt) == 'Y');
break;
}
case 2 : {
opt = 'Y';
do
{
val = del_q(queue, front, rear);
if(val != -1)
{
cout << "\n\t Value deleted from Queue : " << val;
}
cout << "\n\n\t Delete more elements (Y / N) : ";
cin >> opt;
}while(toupper(opt) == 'Y');
break;
}
case 3 : {
show_q(queue, front, rear);
break;
}
case 4 : {
exit(0);
}
default : {
cout << "\n\tInvalid Input";
getch();
exit(0);
}
}
clrscr();
}while(choice != 4);
}
return(value);
}
struct node
{
int data;
node *next;
};
class stack
{
node *top;
public:
stack()
{
top = NULL;
}
void push();
void pop();
void disp();
~stack();
};
temp->next = top;
top = temp;
}
while(temp != NULL)
{
cout << '\t' << temp->data;
temp = temp->next;
}
getch();
}
void main()
{
stack st;
int choice;
do
{
cout << "\n\n\t\t MAIN MENU";
cout << "\n\t\t-----------\n";
cout << "\n\t 1. Push";
cout << "\n\t 2. Pop";
cout << "\n\t 3. Display";
cout << "\n\t 4. Exit";
cout << "\n\n\t Enter choice : ";
cin >> choice;
switch(choice)
{
case 1 : {
st.push();
break;
}
case 2 : {
st.pop();
break;
}
case 3 : {
st.disp();
break;
}
default : {
cout << "Invalid Input";
getch();
exit(0);
}
}
clrscr();
}while(choice != 4);
} /*Destructor function will be called automatically
when the scope of the object gets over*/
DYNAMIC QUEUE :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h> //For exit();
struct node
{
int data;
node *next;
};
class queue
{
node *rear, *front;
public:
queue()
{
rear = NULL;
front = NULL;
}
void qinsert();
void qdelete();
void qdisplay();
~queue();
};
temp->next = NULL;
if(rear == NULL)
{
rear = temp;
front = temp;
}
else
{
rear->next = temp;
rear = temp;
}
}
void queue :: qdelete()
{
if(front != NULL)
{
node *temp = front;
cout << "\n\t" << front->data << " has been deleted";
front = front->next;
delete temp;
if(front == NULL)
{
rear = NULL;
}
}
else
{
cout << "\n\t" << "Queue is empty";
}
getch();
}
while(temp != NULL)
{
cout << '\t' << temp->data;
temp = temp->next;
}
getch();
}
queue :: ~queue()
{
while(front != NULL)
{
node *temp = front;
front = front->next;
delete temp;
}
}
void main()
{
queue qu;
int choice;
do
{
cout << "\n\n\t\t MAIN MENU";
cout << "\n\t\t-----------\n";
cout << "\n\t 1. Insert";
cout << "\n\t 2. Delete";
cout << "\n\t 3. Display";
cout << "\n\t 4. Exit";
cout << "\n\n\t Enter choice : ";
cin >> choice;
switch(choice)
{
case 1 : {
qu.qinsert();
break;
}
case 2 : {
qu.qdelete();
break;
}
case 3 : {
qu.qdisplay();
break;
}
default : {
cout << "Invalid Input";
getch();
exit(0);
}
}
clrscr();
}while(choice != 4);
} /*Destructor function will be called automatically
when the scope of the object gets over*/