Following is C like Pseudo code of a function that takes a number as an argument, and uses a stack S to do processing.
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(!is Empty(&S))
printf("%d",pop(&S));//pop an element from S and print it
}
What does the above function do in general ?
- Prints binary representation of $n$ in reverse order.
- Prints binary representation of $n$.
- Prints the value of $\log n$.
- Prints the value of $\log n$ in reverse order.