Q. A Stack STK and Queue QUE is being maintained. Their maximum size is the same:

(i) Check whether they have the same size, i.e., have the same number of elements.

(ii) Check for equality of Stack and Queue, i.e.


(a) Retrieve an element from the Stack and one element from the Queue.
(b) Compare the two.
(c) Stop and report if elements are different.

Answer =

STK = eval(input("Enter a stack :- "))
QUE = eval(input("Enter a queue :-"))

#(i)
if len(STK) == len(QUE) :
    print("Both have same size ")
else :
    print("Both have different size ")

#(ii)
    #(a)

stack_element = STK[ -1 ]
queue_element = QUE[ 0 ]

    #(b)
if stack_element == queue_element :
    print("Both have same element ")

    #(c)
else :
    print("Both have different element ")


Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post