• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Data Structures | Stack | Question 1

Following is C like pseudo code of a function that takes a number as an argument, and uses a stack S to do processing. C
void fun(int n)
{
    Stack S;  // Say it creates an empty stack S
    while (n > 0)
    {
      // This line pushes the value of n%2 to stack S
      push(&S, n%2);

      n = n/2;
    }

    // Run while Stack S is not empty
    while (!isEmpty(&S))
      printf(\"%d \", pop(&S)); // pop an element from S and print it
}
What does the above function do in general?

(A)

Prints binary representation of n in reverse order

(B)

Prints binary representation of n

(C)

Prints the value of Logn

(D)

Prints the value of Logn in reverse order

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments