stacks and queues stackType stack int x y stackinitializeSta

[stacks and queues]

stackType stack;
int x, y;

stack.initializeStack();

x = 4;
y = 2;
stack.push(6);
stack.push(x);
stack.push(x + 1);
stack.pop(y);
stack.push (x + y);
stack.pop(x);
print(\"x = “, x)

What is the output of the above code? (In Python)

Solution

#! /usr/bin/python
stackType stack
int x, y;
stack.initializeStack();
x = 4;
y = 2;
stack.push(6);       #6 is pushed to stack.
stack.push(x);       #4 is pushed to stack.
stack.push(x + 1);   #5 is pushed to stack.
stack.pop(y);       #2 is pushed to stack.
stack.push (x + y);   #6 is pushed to stack.
stack.pop(x);       #The top element i.e., 6 is popped from stack, and stored to x.
print(\'x = \', x)   #Prints the value of x, i.e., 6 is printed.

[stacks and queues] stackType stack; int x, y; stack.initializeStack(); x = 4; y = 2; stack.push(6); stack.push(x); stack.push(x + 1); stack.pop(y); stack.push

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site