📄 lsnode.h
字号:
//链式堆栈
typedef struct snode
{
DataType data;
struct snode *next;
}LSNode;
void StackInitiate(LSNode **head) //初始化
{
if((*head=(LSNode *)malloc(sizeof(LSNode)))==NULL)
exit(1);
(*head)->next=NULL;
}
int StackNotEmpty(LSNode *head) //是否为空
{
if(head->next==NULL) return 0;
else return 1;
}
int StackPush(LSNode *head,DataType x) //入栈
{
LSNode *p;
if((p=(LSNode *)malloc(sizeof(LSNode)))==NULL)
{
printf("无法插入元素,内层空间不足!\n");
return 0;
}
p->data=x;
p->next=head->next;
head->next=p;
return 1;
}
int StackPop(LSNode *head,DataType *d) //出栈
{
LSNode *p=head->next;
if(p==NULL)
{
printf("元素无法出栈,堆栈已空!\n");
return 0;
}
head->next=p->next;
*d=p->data;
free(p);
return 1;
}
int StackTop(LSNode *head,DataType *d) //取栈顶元素
{
LSNode *p=head->next;
if(p==NULL)
{
printf("无法取栈顶元素,堆栈已空!\n");
return 0;
}
*d=p->data;
return 1;
}
void Destroy(LSNode *head) //撤消
{
LSNode *p,*q;
p=head;
while(p!=NULL)
{
q=p;
p=p->next;
free(q);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -