?? 鏈棧.cpp
字號:
#include<iostream.h>
#include<stdlib.h>
//定義鏈棧結構
typedef struct node
{
char data;
struct node *next;
}seqstack;
typedef seqstack *stack;
//棧的初始化
int initstack(stack &top)
{
top=(seqstack *)malloc(sizeof(seqstack));
top->next=0;return(1);
}
//鏈棧的進棧操作
int push(stack &top,int x)
{
seqstack *p;
p=(seqstack *)malloc(sizeof(seqstack));
if(p==NULL) return 0;
p->data=x; p->next=top->next;
top->next=p;
return 1;
}
//鏈棧的出棧操作
int pop(stack top,int &x)
{
seqstack *p;
p=top->next;
if(p==NULL) /*棧為空*/
return(0);
top->next=p->next;
x=p->data;
free(p); /* 釋放存儲空間 */
return(x);
}
void main()
{
stack top;
int x;
initstack(top);
push(top,2);
push(top,3);
pop(top,x);cout<<x<<endl;
pop(top,x);cout<<x<<endl;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -