随便写个堆栈存取和打印的函数呀。
#define NULL 0
struct node
{
int data;
struct node *next;
};
typedef struct node list;
typedef list *link;
link stack=NULL;
void push()
{int value;
link newnode;
printf("please input the data of the stack\n");
scanf("%d",&value);
newnode=(link)malloc(sizeof(list));
newnode->data=value;
newnode->next=stack;
stack=newnode;
}
void pop()
{link top;
if("stack!=NULL")
{
top=stack;
stack=stack->next;
free(top);
}
else
printf("this stack is empty\n");
}
void print()
{link temp=NULL;
temp=stack;
if(temp==NULL)
printf("this stack is empty\n");
else
{
while(temp!=NULL)
{
printf("%d\n",temp->data);
temp=temp->next;
}
}
}
void main()
{link point;
int select;
printf("1)input a stack data\n");
printf("2)output a stack data\n");
printf("3)print current stack data\n");
printf("other is exit\n");
scanf("%d",&select);
while(select==1||select==2||select==3)
{
switch(select)
{ case 1: push();
break;
case 2: pop();
break;
case 3:print();
break;
}
printf("1)input a stack data\n");
printf("2)output a stack data\n");
printf("3)print current stack data\n");
printf("other is exit\n");
scanf("%d",&select);
};
}