#include<stdio.h>
#include<stdlib.h>
#define N 50
typedef struct
{
int a[N];
int top;
}seqstack_t;
/*创建空顺序栈*/
seqstack_t* creatEmpty ()
{
seqstack_t* p = malloc(sizeof(seqstack_t));
if (p == NULL)
{
return NULL;
}
p->top = 0;
return p;
}
/*入栈*/
void Intoseq (seqstack_t* p,int x)
{
if(isFullseq(p))
{
printf("isFullseq\n");
return ;
}
p->a[p->top] = x;
p->top++;
}
/*出栈*/
void outseq (seqstack_t* p)
{
p->top--;
while(p->top >= 0)
{
printf("%d ",p->a[p->top]);
p->top--;
}
printf("\n");
}
/*删除元素*/
void delseq (seqstack_t* p)
{
p->top--;
}
/*判断是否满*/
int isFullseq (seqstack_t* p)
{
if(p->top >= N)
{
return 1;
}
else
{
return 0;
}
}
/*将10进制数转换2进制数存入栈表*/
void myvoid (seqstack_t* p,int x)
{
int num;
while(x!=0)
{
num = x % 2;
Intoseq(p,num);
x /= 2;
}
}
int main(int argc, const char *argv[])
{
seqstack_t* p = creatEmpty();
myvoid(p,254);
outseq(p);
return 0;
}
顺序栈存储
最新推荐文章于 2024-10-29 09:45:51 发布