#栈
#include<stdio.h>
#define Maxsize 20
typedef int Datatype;
typedef struct{
Datatype data[Maxsize];
int top;
}stack;
void push(stack*s,int x){//压入元素
if(s->top==Maxsize-1){
printf("栈已满");
}
s->top++;
s->data[s->top] = x;
}
Datatype pop(stack *s){//获取栈顶元素
int x;
if(s->top==-1){
printf("栈已空");
}
x=s->data[s->top--];
return x;
}
void isEmpty(stack*s){//判空
if(s->top==-1){
printf("栈为空\n");
}
printf("栈不为空\n");
}
int isFull(stack*s){//判满
if(s->top==Maxsize-1){
return 1;
}else{
return -1;
}
}
void transfor(stack *s,int num){//转成将数字转换成二进制 用栈存储
int temp;
int top = -1;
while(num!=0){
temp = num%2;
push(s,temp);
num = num/2;
}
while(isEmpty(s)!=1){
printf("%d",pop(s));
}
}