Given standard stack operation. push(S, x), pushes the value x in stack S and…

Given standard stack operation. push(S, x), pushes the value x in stack S and function pop(S) pop the top value from stack S. For any queue Q, let enqueue(Q,x) pushes value x in rear side of queue and dequeue(Q) removes front element from queue. For the given function, what does the following function performs ( Q and S are predefined queue and stack respectively)?
Void fun(int n){
          int x;
          while(n != 0){
                    x =  n%2;
                    enqueue(Q,x);
                    n = n/2;
          }
          while(!isEmpty(Q))
                    push(S, dequeue(Q));
          while(!isEmpty(S))
                    print(“%d”, pop(S));
          print(“\n”);
}

  1. A.

    Print number of 1’s in binary representation of n

  2. B.

    Prints binary representation of n

  3. C.

    Prints binary representation of n in reverse order

  4. D.

    Print number of 0’s in binary representation of n

Attempted by 357 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…