淘宝电商网站怎么做的,当地人做导游的旅游网站,网站开发 数字证书,邢台市网站制作数据结构——堆栈的C实现\qquad堆栈的创建、判断是否为空#xff0c;入栈#xff0c;出栈操作的C实现。
#includeiostream
using namespace std;//1.定义
typedef struct Node* Link;
struct Node {int num;Link next;
};//2.创建堆栈头结点
Link CreateStack()
{Li…数据结构——堆栈的C实现
\qquad堆栈的创建、判断是否为空入栈出栈操作的C实现。
#includeiostream
using namespace std;//1.定义
typedef struct Node* Link;
struct Node {int num;Link next;
};//2.创建堆栈头结点
Link CreateStack()
{Link s;s new Node;s-next NULL;return s;
}//3.判断堆栈是否为空
int IsEmpty(Link s)
{return(s-next NULL);
}//4.入栈
void Push(int num, Link s)
{Link L;L new Node;L-num num;L-next s-next;s-next L;
}//5.出栈并返回出栈数据
int Pop(Link s)
{Link firstcell;int topnum;if (IsEmpty(s)) {cout 堆栈空 endl;return NULL;}else {firstcell s-next;s-next firstcell-next;topnum firstcell-num;delete firstcell;return topnum;}
}
int main()
{Link top;int i;//创建堆栈头结点top CreateStack();//将数据1,2,3,4,5压入栈中for (i 1; i 6; i) {Push(i, top);Link top2 top-next;cout top2-num endl;}//将堆栈上两个数据弹出栈for (i 1; i 3; i) {cout Pop(top) endl;}}