You are on page 1of 3

#include "conio.

h"
#include "stdio.h"
#define max 100

struct Stack
{
char A[max];
int top=-1;
};

int kiemtraday (Stack s)


{
if (s.top == max-1)
return 1;
return 0;
}

int kiemtrarong (Stack s)


{
if (s.top == -1)
return 1;
return 0;
}

void push (Stack &s, int x)


{
if (kiemtraday (s) == 1)
{
printf ("stack day");
return;
}
s.top +=1;
s.A[s.top] = x;
}

int pop (Stack &s)


{
if (kiemtrarong(s) == 1)
{
printf ("stack rong");
return -1;
}
int x;
x = s.A[s.top];
s.top = s.top -1;
return x;
}
int main(){
int n;
int x;

Stack s;
printf("Nhap vao n:\n");
scanf("%d",&n);
while(n>0){
if(n%2==0)
push(s,0);
else
push(s,1);
n=n/2;
}
printf("Nhi phan tuong ung la:\n");
while(kiemtrarong(s)!=1){
x=pop(s);
printf("%d",x);
}
return 0;
}

You might also like