LAB # 6 (DATA STRUCTURE AND OBJECT ORIENTED PROGRAMING)
LAB # 6
CoNTeNT
TASK Write a program that performs the queue operations?
TASK Write a program to demonstrate inline function?
TASK Write a program using & pointer operator?
TASK Write a program to explain & * operator?
TASK Write a program that performs the queue operations?
CODE
#include <iostream>
#include <conio.h>
#define max 3
using namespace std;
void push (int a[max]);
void pop (int a[max]);
void peek (int a[max]);
void display (int a[max]);
int front =-1,rear=-1;
class queueimpt
{
public:
void push(int a[max])
{
int item;
cout<<"enter item";
cin>>item;
if (rear==max)
cout<<"queue overflow\n";
else
{
if (front==-1)
front =0;
rear++;
a[rear]=item;
}
}
void peek(int a[max])
{
cout<<"peek element"<<a[front]<<endl;
}
void pop(int a[max])
{
int item1;
if(front==-1||front>rear)
cout<<"queue underflow\n";
else
{
item1=a[front];
cout<<"element
deleted"<<"a["<<front<<"]="<<item1<<endl;
++front;
}
}
void display(int a[max])
{
int Null;
if(front==Null)
{
cout<<"queue empty\n";
}
else
{
cout<<"queue's elements";
for(int k=front;k<=rear;k++)
cout<<"a["<<k<<"]="<<a[k]<<endl;
}
}
int main()
{
queueimpt obj;
int a[max];
int j;
char ch;
do
{
cout<<"1. push\n 2. pop\n 3.
peek\n 4.display\n";
cout<<"Enter your choice";
cin>>j;
switch(j)
{
case 1:obj.push(a);break;
case 2:obj.pop(a);break;
case 3:obj.peek(a);break;
case 4:obj.display(a);break;
defaut:
cout<<"invalid
choice";break;
}
cout<<"do you want to
continue(y/n)";
cin>>ch;
}while(ch=='y'||ch=='y');
getch();
return 0;
}
OUTPUT
Comments
Post a Comment