全部博文(156)
分类: C/C++
2010-10-03 16:08:23
#include
#include
#define N 6
typedef int datatype;
typedef struct
{
datatype data[N];
int top;
} seqstack;
seqstack *CreateEmptyStack_1()
{
seqstack *s;
s = (seqstack *)malloc(sizeof(seqstack));
s->top = -1;
return s;
}
void CreateEmptyStack_2(seqstack **s)
{
*s = (seqstack *)malloc(sizeof(seqstack));
(*s)->top = -1;
return;
}
int EmptyStack(seqstack *s)
{
return (-1 == s->top);
}
int FullStack(seqstack *s)
{
return (N-1 == s->top);
}
void ClearStack(seqstack *s)
{
s->top = -1;
}
void PushStack(seqstack *s, datatype x)
{
s->top++;
s->data[s->top] = x;
return;
}
datatype PopStack(seqstack *s)
{
s->top--;
return s->data[s->top+1];
}
datatype GetTop(seqstack *s)
{
return s->data[s->top];
}
int main()
{
int i;
seqstack *s;
s = CreateEmptyStack_1();
scanf("%d", &i);
while (i > 0)
{
PushStack(s, i % 16);
i = i / 16;
}
printf("0x");
while ( ! EmptyStack(s) )
{
printf("%d", PopStack(s));
}
printf("\n");
return 0;
}