Devus 3
Devus 3
Devus 3
2313711058011
#include<iostream.h>
#include<conio.h>
int stack[10],size,p,top=0;
void main(){
void push(int);
int pop();
void display();
int item,choice;
char response='y';
clrscr();
cout<<"enter size of the stack:";
cin>>size;
while(response=='y') {
cout<<"MENU:"<<endl<<"1.PUSH\n2.POP\n3.DISPLAY"<<endl;
cout<<"enter choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter item:";
cin>>item;
push(item);
break;
case 2:
p=pop();
break;
case 3:
display();
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"do you want to continue? y/n"<<endl;
cin>>response;
}
}
void push(int i){
if(top==size){
cout<<"Stack is full"<<endl;
}
else {
top++;
stack[top]=i;
}
}
int pop()
{
if(stack[top]==0){
cout<<"Stack is empty"<<endl;
}
else {
int popval;
popval=stack[top];
top--;
cout<<"Item is poped"<<endl;
return popval;
}
}
void display(){
clrscr();
cout<<"PROGRAM TO ILLUSTRATE STACK DATA STRUCTURE"<<endl<<endl;
cout<<"SIZE OF STACK:"<<size<<endl;
cout<<"POPED ITEM :"<<p<<endl;
cout<<"STACK:"<<endl;
for(int i=top;i>=1;i--){
cout<<stack[i]<<endl;
}
}
Devayani MM
2313711058011
#include<iostream.h>
#include<conio.h>
class Stack{
int stack[10];
int size;
int popval;
int top;
public:
void getdata(int,int);
void push(int);
int pop();
void display();
};
void Stack::getdata(int t,int si){
top=t;
size=si;
popval=0;
}
void Stack::push(int i){
if(top==size){
cout<<"Stack is full"<<endl;
}
else {
top++;
stack[top]=i;
}
}
int Stack::pop()
{
if(stack[top]==0){
cout<<"Stack is empty"<<endl;
return 0;
}
else {
popval=stack[top];
top--;
cout<<"Item is Poped"<<endl;
return popval;
}
}
void Stack::display(){
clrscr();
cout<<"PROGRAM TO ILLUSTRATE STACK DATA STRUCTURE USING CLASS"<<endl<<endl;
cout<<"SIZE OF STACK:"<<size<<endl;
cout<<"POPED ITEM :"<<popval<<endl;
cout<<"STACK:"<<endl;
for(int i=top;i>=1;i--) {
cout<<stack[i]<<endl;
}
}
void main(){
int t=0,size;
Stack s;
int item,choice;
char response='y';
clrscr();
cout<<"enter size of the stack:";
cin>>size;
s.getdata(t,size);
while(response=='y') {
cout<<"MENU:"<<endl<<"1.PUSH\n2.POP\n3.DISPLAY"<<endl;
cout<<"enter choice:";
cin>>choice;
switch(choice){
case 1:
cout<<"enter item:";
cin>>item;
s.push(item);
break;
case 2:
s.pop();
break;
case 3:
s.display();
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"do you want to continue? y/n"<<endl;
cin>>response;
}
}
Devayani MM
2313711058011
QUEUE
#include<iostream.h>
#include<conio.h>
int queue[10],size,front=0,rear=0,item,x;
void main()
{
void addq(int);
int deleteq();
void display();
int item,choice;
char response='y';
clrscr();
cout<<"enter size of the queue:";
cin>>size;
while(response=='y')
{
cout<<"MENU:"<<endl<<"1.ADD\n2.DELETE\n3.DISPLAY"<<endl;
cout<<"enter choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter item:";
cin>>item;
addq(item);
break;
case 2:
x=deleteq();
break;
case 3:
display();
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"do you want to continue? y/n"<<endl;
cin>>response;
}
}
void addq(int item)
{
if(rear==size)
cout<<"queue is full"<<endl;
else
rear++;
queue[rear]=item;
}
int deleteq()
{
if(front==rear)
{
cout<<"queue is empty"<<endl;
return 0;
}
else
{
front++;
item=queue[front];
cout<<"ITEM DELETED"<<endl;
return item;
}
}
void display()
{
clrscr();
cout<<"PROGRAM TO ILLUSTRATE QUEUE DATA STRUCTURE"<<endl<<endl;
cout<<"SIZE OF QUEUE:"<<size<<endl;
cout<<"QUEUE:"<<endl;
for(int i=front+1;i<=rear;i++)
cout<<queue[i]<<endl;
cout<<"ITEM DELETED:"<<x<<endl;
}
Devayani MM
2313711058011
#include<iostream.h>
#include<conio.h>
class queue{
int queue[10];
int x;
int size;
int front;
int rear;
public:
void getdata(int);
void addq(int);
int deleteq();
void display();
};
void queue::getdata(int si)
{
size=si;
front=0;
rear=0;
x=0;
}
void queue::addq(int i)
{
if(rear==size)
{
cout<<"queue is full"<<endl;
}
else
{
rear=rear+1;
queue[rear]=i;
}
}
int queue::deleteq()
{
if(front==rear)
{
cout<<"queue is empty"<<endl;
return 0;
}
else
{
front++;
x=queue[front];
cout<<"ITEM DELETED"<<endl;
return x;
}
}
void queue::display()
{
clrscr();
cout<<"PROGRAM TO ILLUSTRATE QUEUE DATA STRUCTURE USING CLASS"<<endl<<endl;
cout<<"SIZE OF QUEUE:"<<size<<endl;
cout<<"QUEUE:"<<endl;
for(int i=front+1;i<=rear;i++)
cout<<queue[i]<<endl;
cout<<"ITEM DELETED:"<<x<<endl;
}
void main()
{
int item,choice,size;
queue q;
clrscr();
cout<<"enter size of the queue:";
cin>>size;
q.getdata(size);
char response='y';
while(response=='y')
{
cout<<"MENU:"<<endl<<"1.ADD\n2.DELETE\n3.DISPLAY"<<endl;
cout<<"enter choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter item:";
cin>>item;
q.addq(item);
break;
case 2:
q.deleteq();
break;
case 3:
q.display();
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"do you want to continue? y/n"<<endl;
cin>>response;
}
}
Devayani MM
2313711058011
CIRCULAR QUEUE
#include<iostream.h>
#include<conio.h>
int queue[10],size,front=0,rear=0,x;
void main(){
void caddq(int);
void cdeleteq();
void display();
int item,choice;
char response='y';
clrscr();
cout<<"enter size of the queue:";
cin>>size;
clrscr();
cout<<"PROGRAM TO ILLUSTRATE CIRCULAR QUEUE DATA STRUCTURE"<<endl<<endl;
while(response=='y') {
cout<<"MENU:"<<endl<<"1.ADD\n2.DISPLAY\n3.DELETE"<<endl;
cout<<"enter choice:";
cin>>choice;
switch(choice) {
case 1:
cout<<"enter item:";
cin>>item;
caddq(item);
break;
case 2:
display();
break;
case 3:
cdeleteq();
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"do you want to continue? y/n"<<endl;
cin>>response;
}
}
void caddq(int item)
{
int prear;
prear=rear;
rear=(rear+1)%size;
if(front==rear){
cout<<"Queue is full"<<endl;
rear=prear;
}
else{
queue[rear]=item;
}
}
void cdeleteq(){
int item;
if(front==rear){
cout<<"Queue is empty"<<endl;
front=rear=0;
}
else{
front=(front+1)%size;
item=queue[front];
cout<<"ITEM DELETED:"<<item<<endl;
}
}
void display(){
cout<<"QUEUE:"<<endl;
for(int i=front+1;i<=rear;i++){
cout<<queue[i]<<endl;
}
}
Devayani MM
2313711058011
#include<iostream.h>
#include<conio.h>
class queue
{
int queue[10];
int size;
int front;
int rear;
public:
void getdata(int);
void caddq(int);
void cdeleteq();
void display();
};
void queue::getdata(int si)
{
front=0;
rear=0;
size=si;
}
void queue::caddq(int item)
{
int prear;
prear=rear;
rear=(rear+1)%size;
if(front==rear)
{
cout<<"Queue is full"<<endl;
rear=prear;
}
else
{
queue[rear]=item;
}
}
void queue::cdeleteq()
{
int item;
if(front==rear)
{
cout<<"Queue is empty"<<endl;
front=rear=0;
}
else
{
front=(front+1)%size;
item=queue[front];
cout<<"ITEM DELETED:"<<item<<endl;
}
}
void queue::display()
{
cout<<"QUEUE:"<<endl;
for(int i=front+1;i<=rear;i++)
{
cout<<queue[i]<<endl;
}
}
void main()
{
queue q;
int size;
int item,choice;
char response='y';
clrscr();
cout<<"enter size of the queue:";
cin>>size;
q.getdata(size);
clrscr();
cout<<"PROGRAM TO ILLUSTRATE CIRCULAR QUEUE DATA STRUCTURE USING CLASS"<<endl<<endl;
while(response=='y')
{
cout<<"MENU:"<<endl<<"1.ADD\n2.DISPLAY\n3.DELETE"<<endl;
cout<<"enter choice:";
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter item:";
cin>>item;
q.caddq(item);
break;
case 2:
q.display();
break;
case 3:
q.cdeleteq();
break;
default:
cout<<"invalid choice"<<endl;
}
cout<<"do you want to continue? y/n"<<endl;
cin>>response;
}
}