#include<stdio.h>
#include<malloc.h>
typedef struct node;
void push(node* head,int newdata);
void pop(node* head);
int top(node* head);
int is_empty(node* head);
typedef struct node
{
int data;
struct node* next;
};
void push(node* head,int newdata)
{
node* p=(node*)malloc(sizeof(node));
p->data=newdata;
p->next=head->next;
head->next=p;
}
void pop(node* head)
{
node* temp=head->next;
head->next=temp->next;
free(temp);
}
int top(node* head)
{
return head->next->data;
}
int is_empty(node* head)
{
if(head->next==0ll)return 1;
return 0;
}
int main()
{
node* Stack=(node*)malloc(sizeof(node));
Stack->next=0ll;
int n;
while(scanf("%d",&n)!=-1){
if(n==0){
puts("0");
continue;
}
while(n){
push(Stack,n&1);
n>>=1;
}
while(!is_empty(Stack)){
printf("%d",top(Stack));
pop(Stack);
}
puts("");
}
return 0;
}
stacks-Data Structures Using C
最新推荐文章于 2024-07-13 15:38:02 发布