stack2.h
来自「自己做的数据结构实验题(合并链表」· C头文件 代码 · 共 58 行
H
58 行
#include<stdio.h>
#include<malloc.h>
typedef char ElemType;
typedef struct Node{
ElemType data;
Node *next;
}Node;
typedef Node *Stack,*Position;
//Create a stack
Stack CreateStack()
{
Node *S;
S=(Stack)malloc(sizeof(Node));
S->next=NULL;
return S;
}
//Push element into stack
void Push(Stack S,ElemType e){
Node *TempCell;
TempCell=(Node*)malloc(sizeof(Node));
TempCell->data=e;
TempCell->next=S->next;
S->next=TempCell;
}
//put the top element of stack out
void Pop(Stack S,ElemType &e){
if(S->next!=NULL)
e=S->next->data;
Position a=S->next;
S->next=S->next->next;
free(a);
}
void ClearStack(Stack S){
Position p,q;
q=p=S->next;
while(p){
p=p->next;
free(q);
q=p;
}
S->next=NULL;
}
int IsEmptyStack(Stack S){
return(S->next==NULL);
}
ElemType Top(Stack S){
return S->next->data;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?