求C语言 栈代码要求有入栈和出栈功能谢谢

来源:百度知道 编辑:UC知道 时间:2024/05/16 18:36:18
求C语言 栈代码要求有入栈和出栈功能谢谢。
完整的能运行的C语言程序,不要伪代码。

#include "stdio.h"

#define MAXLEN 100

typedef struct stacknode
{
int data;
struct stacknode *next;
}stacknode;
typedef struct
{
stacknode *top;
}linkstack;

/*-----------------进栈操作----------------------------------------*/
int Push (linkstack *s,int x)
{
stacknode *p=(stacknode*)malloc(sizeof(stacknode));
p->data=x;
p->next=s->top;
x=p->data;
s->top=p->next;
free(p);
return x;
}
/*-------------出栈操作------------------------------------------*/
int Pop(linkstack *s)
{
int x;
stacknode *p=s->top;
x=p->data;
s->top=p->next;
free(p);
return x;
}
/*---------------显示栈内元素-----------------------------------------*/
void ShowStack (linkstack *s)
{
stacknode *p=s->top;
if(p==NULL)
printf("\t\ts