?? 2.2.c
字號:
#include<stdio.h>
#define NULL 0
struct Node
{int data;
struct Node *next;
};
struct Stack
{struct Node *base;
struct Node *top;
int stacksize;
};
struct Stack S;
void InitStack()
{S.base=NULL;
S.top=NULL;
S.stacksize=0;
}
void Push(int x)
{struct Node *p;
p=(struct Node*)malloc(sizeof(struct Node));
p->data=x;
p->next=S.top;
S.top=p;
S.stacksize++;
}
int StackEmpty()
{if(S.top==NULL)
return 1;
else
return 0;
}
void Pop(int *p)
{*p=S.top->data;
S.top=S.top->next;
S.stacksize--;
}
void conversion()
{int N,e;
InitStack();
scanf("%d",&N);
while(N)
{Push(N%2);
N=N/2;
}
while(!StackEmpty())
{Pop(&e);
printf("%d",e);
}
}
void main(void)
{conversion();
getch();
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -