DSLab Excersices
DSLab Excersices
OUTPUT:
Enter The Size Of STACK [MAX=100] : 2
STACK OPEATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 1
Enter a Value to be Push : 89
89 is Inserted.
The Elements in STACK.
=== ======== == =====
DATA 1=89
Press Any Key to Continue...
STACK OPERATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 1
Enter a Value to be Push : 37
37 is Inserted.
The Elements in STACK.
=== ======== == =====
DATA 1=89
DATA 2=37
Press Any Key to Continue...
STACK OPERATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 1
STACK is Over Flow...
STACK OPERATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 2
Removing a Value...
The Deleted Item is 37
The Elements in STACK.
=== ======== == =====
DATA 1=89
Press Any Key to Continue...
STACK OPERATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 3
The Elements in STACK.
=== ======== == =====
DATA 1=89
Press Any Key to Continue...
STACK OPERATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 2
Removing a Value...
The Deleted Item is 89
The STACK is Empty.
STACK OPERATION
===== =========
1.PUSH
2.POP
3.DISPLAY
4.EXIT
Enter Your Option : 4
Your On Exit...
RESULT:
Thus the stack operation was successfully implemented and executed using C++.
EX.NO:2 EVALUATION OF EXPRESSION
DATE:
AIM:
ALGORITHM:
PROGRAM:
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<ctype.h>
#include<string.h>
int n,j,top;
float v1,v2,v,vstack[100],val[100];
char ch[100],chh,postfix[100];
float pop(float*),compute(float,float,char),eval(char*);
float return_val(char);
void push(float*,float),alpha(char*),getvalue();
void main()
{
clrscr();
cout<<"\n Enter An Postfix Exp : ";
cin>>postfix;
alpha(postfix);
getvalue();
j=0;
chh=postfix[j];
while(chh!='\0')
{
if(isalpha(chh))
{
v=return_val(chh);
push(vstack,v);
}
else
{
if(top!=-1)
v2=pop(vstack);
if(top!=-1)
v1=pop(vstack);
v=compute(v1,v2,chh);
push(vstack,v);
}
j++;
chh=postfix[j];
}
v=pop(vstack);
cout<<"\n The Result is "<<v;
getch();
}
void getvalue()
{
int i;
for(i=0;i<=n;i++)
{
cout<<"\nEnter the value for "<<ch[i]<<":";
cin>>val[i];
}
}
float pop(float* x)
{
float cc;
if(top!=-1)
{
cc=x[top];
top--;
return (cc);
}
return(-1000);
}
RESULT:
Thus the program to evaluate postfix expression was successfully implemented &
executed using C++.
EX.NO:3 IMPLEMENTATION OF QUEUE
DATE:
AIM:
ALGORITHM:
PROGRAM:
#include<iostream.h>
#include<conio.h>
int front,rear;
int queue[200];
int n,choice,x;
void enque(),deque(),view(void);
void main()
{
clrscr();
front=0;
rear=0;
cout<<"\nEnter The Size Of QUEUE [MAX=100] : ";
cin>>n;
do
{
clrscr();
cout<<"\n\t\tQUEUE OPERATION";
cout<<"\n\t\t===== =========";
cout<<"\n\n\t1.ENQUE\n\t2.DEQUE\n\t3.VIEW\n\t4.EXIT";
cout<<"\n\nEnter Your Choice : ";
cin>>choice;
switch(choice)
{
case 1:
{
enque();
break;
}
case 2:
{
deque();
break;
}
case 3:
{
view();
break;
}
case 4:
{
cout<<"\n\n\t\t You Are Exited...";
break;
}
}
getch();
}while(choice!=4);
}
void enque()
{
if(rear>=n)
{
cout<<"\n\t\tQUEUE is Over Flow...";
getch();
}
else
{
cout<<"\nEnter a Value : ";
cin>>x;
queue[rear]=x;
cout<<x<<" is Added.\n";
rear++;
view();
}
}
void deque()
{
if(front>=rear)
{
cout<<"\n\t\tQUEUE is Under Flow...";
}
else
{
cout<<queue[front]<<" is Deleted.\n\n";
front++;
view();
}
}
void view()
{
int i=front,j=rear;
if(i>=j)
{
cout<<"\n\t\tQUEUE is Empty...";
}
else
{
cout<<"\n\n\tData in Queue";
cout<<"\n\t===============";
for(;i<=j-1;i++)
cout<<"\nDATA "<<i+1<<"="<<queue[i];
cout<<"\nPress any key to continue..";
}
}
OUTPUT:
Enter The Size Of QUEUE [MAX=100] : 2
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 1
Enter a Value : 12
12 is Added.
Data in Queue
===============
DATA 1=12
Press any key to continue..
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 1
Enter a Value : 951
951 is Added.
Data in Queue
===============
DATA 1=12
DATA 2=951
Press any key to continue..
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 3
Data in Queue
===============
DATA 1=12
DATA 2=951
Press any key to continue..
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 1
QUEUE is Over Flow...
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 2
12 is Deleted.
Data in Queue
===============
DATA 2=951
Press any key to continue..
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 2
951 is Deleted.
QUEUE is Empty...
QUEUE OPERATION
===== =========
1.ENQUE
2.DEQUE
3.VIEW
4.EXIT
Enter Your Choice : 4
RESULT:
Thus the program to perform queue operation was successfully implemented and
executed using C++.