forked from gods-mack/Workspace
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkstack.cpp
More file actions
67 lines (46 loc) · 698 Bytes
/
linkstack.cpp
File metadata and controls
67 lines (46 loc) · 698 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
using namespace std;
struct node
{ int data;
node *next;
};
class stack
{ node *top;
node *h;
public: stack() { top=NULL; }
void push(int x)
{ node *n=new node;
n->data = x;
n->next=top;
top=n;
}
void print()
{
node *tmp;
tmp=top;
while(tmp!=NULL) {
cout<<tmp->data<<" ";
tmp=tmp->next;
}
}
void pop()
{
node *tmp;
tmp=top; top=top->next;
cout<<tmp->data<<" ";
// tmp=tmp->nextdelete ==========;
delete tmp;
}
};
int main()
{ stack a;
a.push(34);
a.push(87);
a.push(456);
a.push(36546);
a.pop();
a.pop();
a.pop();
cout<<endl;
a.print();
}