📄 test03.txt
字号:
#include <malloc.h>
#define M 10
typedef int Elemtype;
typedef struct NODE
{
Elemtype data;
struct NODE *next;
}SNode;
void InitStact (SNode *&s)
{
s = NULL;
}
void Push(SNode *&s, Elemtype x)
{
SNode* p;
p = (SNode*)malloc(sizeof(SNode));
p->data = x;
p->next = NULL;
if (s == NULL)
{
s = p;
}
else
{
p->next = s;
s = p;
}
}
int GetTop (SNode *s, Elemtype &x)
{
if (s == NULL)
{
return 0;
}
else
{
x = s->data;
s = s->next;
return 1;
}
}
//出栈
int PopStack(SNode *&s, Elemtype &x)
{
SNode *p = s;
if (s == NULL)
{
return 0;
}
else
{
x = s->data;
s = s->next;
free (p);
return 1;
}
return 1;
}
int StackEmpty (SNode *s)
{
if (s == NULL)
{
return 1;
}
return 0;
}
void Display(SNode *p)
{
printf("出栈显示");
while (p != NULL)
{
int x;
PopStack(p, x);
printf("%d-->", x);
}
}
void main()
{
int i;
SNode *p = NULL;
printf("入栈显示");
for (i=0; i<10; i++)
{
Push(p, i);
printf("%d-->", i);
}
printf("\n");
Display(p);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -