单项选择题
下列的C++程序使用栈对参数n进行处理后输出,输出的结果是( )。
#include
using namespace std;
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
S.push(n%2);
n = n/2;
}
// Run while Stack S is not empty
while (!S.empty())
{
printf("%d ", S.top()); // print it
S.pop(); //pop an element from S
}
A. 输出n的二进制的逆序
B. 输出n的二进制表示
C. 输出logn的数值
D. 输出n^2的值