/*顺序栈的初始化*/
#include
#include
#include
#define stack_size 3
#define error -1
typedef struct student{
int num;
char name[10];//定义数组时开辟了空间
}student,*Student;//栈中的元素
typedef struct linkstack
{
student children[100];
int top;
int base;
int stacksize;
}stack,*Stack;//栈的特性
stack* initstack(int stasize)
{
int i;
stack List;
stack* list;
List.base=0;
List.top=0;
List.stacksize=stasize;//初始化一个空栈
for(i=0;i<stasize;i++)
{
printf("请输入姓名");
scanf("%s",((List.children[i]).name));//数组指针的用法
printf("请输入学号");
scanf("%d",&List.children[i].num);
}
List.top=stasize;
list=&List;//应该是这附近出现问题
return (list);
}
int push(stack* p,Student x)
{
if(p->top-p->base==p->stacksize)
p->stacksize++;
p->top=p->top+1;
//p[statype->top]=*x;//可能有问题,关于结构体赋值的问题
//p[statype->top].name=x->name;
strcpy(p->children[p->top].name,x->name);
p->children[p->top].num=x->num;
}
int pop(Stack statype)
{
if(statype->top=statype->base)
exit(error);
statype->top=statype->top-1;
return 0;
}
int main(void)
{
stack* initstack(int stasize);
int push(stack* p,Student x);
//int pop(Stack statype);
stack* list=initstack(stack_size);
Student x;
x=(student*)malloc(sizeof(student));
strcpy(x->name,"liuyun");
push(list,x);
return 0;
}