Académique Documents
Professionnel Documents
Culture Documents
in
KVSeContents.in
8
step6:Push
12
8
step7:Push
3
push result
16
step 8 :Pop
0rp2=3
12
12
12
12
16
16
16
16
Pop
0rp1=12
then 123=9
Push
result=9
9
16
step9 :
+
Pop
0rp2=9
9
16
60
Pop
0rp1=16
then
16+9=25
Push
result
25
Pop the
Result=25
3) Write a function in C++ to perform Push operation on
KVSeContents.in
[AI 2008]
KVSeContents.in
}
}
6) Write a function in C++ to insert an element into a dynamically
KVSeContents.in
5
10
4
10
4
5
10
4
0rp2=5
5
10
4
Pop
0rp1=10
then
10+5
result
15
4
step 5 :*
Pop
0rp1=4
then 15*5
result
Pop
0rp2=15
15
4
15
4
step6:Push
15
60
step7:Push 3
3
15
60
15
60
step 8 :/
3
15
60
Pop
0rp2=3
5
15
60
Pop
0rp1=15
then 15/3
result
step9 :
Pop
0rp2=5
5
60
5
60
Pop
0rp1=60
then 60-5
result
55
8) Write a function in C++ to Delete an element into a dynamically allocated Queue where each node
contains a real number as data.
[OUTSIDE DELHI 2008:]
Assume the following definition of MYNODE for the same:
struct MYNODE
{
5
60
KVSeContents.in
float NUM;
MYNODE * Link;
};
Solution:
struct MYNODE
{
float NUM;
MYNODE *Link;
};
class Queue
{
MYNODE *front,*rear;
public:Queue( )
{ front=rear=NULL; }
void Insert( );
void Delete( );
void Display( );
};
void Queue::Delete( )
{
MYNODE *temp;
if(front= = NULL)
cout<<Queue Underflow;
else
{
cout<<\nThe content of the element to
delete:<<frontNUM;
temp=front;
front=front->Link;
delete temp;
}
}
9) Evaluate the following postfix notation of expression (Show
5
*
7
8
25
25
Action
Push
Push
Push
Pop twise(Binary
operator
Push
Pop twise(Binary
operator
Push
Push
Stack
status
5
5 20
5 20 15
5
Intermediate
output
20-15=5
5 5
5*5=25
25
25 25
KVSeContents.in
9
10
2
*
11
12
50
+
75
Push
Pop twise(Binary
operator
Push
Pop twise(Binary
operator
Push
No More Element
25 25 2
25
25*2=50
25 50
25+50=75
75
75 result
- / 6 * 10+
Solution:
KVSeContents.in
step
1
2
3
4
Input
symbols
25
8
3
-
5
6
5
/
7
8
9
5
6
*
10
11
12
30
10
+
40
Action
Push
Push
Push
Pop twise(Binary
operator
Push
Pop twise(Binary
operator
Push
Push
Pop twise(Binary
operator
Push
Push
Pop twise(Binary
operator
Push
No More Element
Stack
status
25
25 8
25 8 3
25
Intermediate
output
8-3=5
25 5
25/5=5
5
5 6
5*6=30
30
30 10
30+10=40
40
40 result
KVSeContents.in
void Display( );
};
void Queue::Delete( )
{ Customer *Temp;
if(front= =NULL)
cout<<Queue Underflow. No element to delete;
else
{ cout<<\n The customer number for the element to
delete.<<front->CNo;
cout<<\n The customer name for the element to
delete<<frontCName;
Temp=front;
front = front->Link;
delete Temp;
}
}
13) Evaluate the following postfix notation of expression : 15 3 2
+ / 7 + 2. *
Solution:
step
Input
symbols
1
15
2
3
3
2
4
+
5
6
5
/
7
8
7
+
9
10
11
10
2
*
12
20
Action
Push
Push
Push
Pop twice(Binary
operator
Push
Pop twice(Binary
operator
Push
Pop twice(Binary
operator
Push
Push
Pop twice (Binary
operator
Push
No More Element
Stack
status
15
15 3
15 3 2
15
Intermediate
output
3+2=5
15 5
15/5=3
3 7
3+7=10
10
10 2
10*2=20
20
20 result