📄 lstack.h
字号:
/*lstack.h*/
#include"sj.h" /*调用自定义库函数*/
typedef struct node{
ElemType data;
struct node *next;
}StackNode;
typedef struct
{
struct node *top;
}LinkStack;
void Init_LS(LinkStack *ls) /*置空链栈 */
{ ls->top=NULL;
}
Status Empty_LS(LinkStack *ls) /*判栈空 */
{ return ls->top==NULL;
}
void Push_LS(LinkStack *ls, ElemType x) /*入栈 */
{ StackNode *p=(StackNode *)malloc(sizeof(StackNode));
p->data=x;
p->next=ls->top; /* 将元素x插入链栈顶 */
ls->top=p ;
}
Status Pop_LS(LinkStack *ls, ElemType *y) /* 出栈*/
{ StackNode *p;
if (Empty_LS(ls))
{ printf ("下溢!") ;
return OVERFLOW;
}
else { *y=ls->top->data ;
p=ls->top ;
ls->top=p->next;
free (p) ;
return OK ;
}
}
Status GetTop(LinkStack *ls, ElemType *y) /*取栈顶元素 */
{ if( Empty_LS(ls) )
{ printf ("下溢!") ;
return OVERFLOW;
}
else {
*y=ls->top->data;
return OK ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -