数据结构之栈的基本操作(c++)

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <stdlib.h>
 4 typedef struct Lnode
 5 {
 6     int data;
 7     struct Lnode *next;
 8 }Lnode;
 9 using namespace std;
10 
11 int main()
12 {
13     void Push(Lnode *&lst,int e);
14     int Pop(Lnode *&lst,int &x);
15     int a[8]={2,9,7,23,8,68,35,19};
16     int i,x;
17     Lnode *lst;
18     lst=(Lnode*)malloc(sizeof(Lnode));
19     lst->next=NULL;
20     for(i=0;i<8;i++)
21     Push(lst,a[i]);
22     while(Pop(lst,x))
23     {
24         cout <<x<< endl;
25     }
26     return 0;
27 }
28 void Push(Lnode *&lst,int e)
29 {
30     Lnode *p;
31     p=(Lnode*)malloc(sizeof(Lnode));
32     p->next=NULL;
33     p->data=e;
34     p->next=lst->next;
35     lst->next=p;
36 }
37 int Pop(Lnode *&lst,int &x)
38 {
39     if(lst->next==NULL)
40     return 0;
41     Lnode *p;
42     p=lst->next;
43     x=p->data;
44     lst->next=p->next;
45     free(p);
46     return 1;
47 }

仅供参考。。。

原文地址:https://www.cnblogs.com/nannanITeye/p/3053242.html