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
54
55
56
57
|
#include<iostream>
using namespace std;
class Node
{
private:
int data;
Node* next;
public:
void push(int x);
int pop();
void Display();
}*top=NULL;
void Node::push(int x)
{
Node* t = new Node;
if (t == NULL)
cout << "pull stack";
t->data = x;
t->next = top;
top = t;
}
int Node::pop()
{
Node* t = top;
int x = -1;
if (top == NULL)
cout << "empty";
else
{
x = t->data;
top = top->next;
delete t;
}
return x;
}
void Node::Display()
{
Node* t = top;
while (t)
{
cout << t->data << " ";
t = t->next;
}
}
int main()
{
Node s;
s.push(10);
s.push(20);
s.push(30);
cout << s.pop()<<endl;
s.Display();
return 0;
}
|
cs |
'알고리즘' 카테고리의 다른 글
Queue (0) | 2022.11.07 |
---|---|
Link stack 최종 (0) | 2022.10.30 |
ADT stack (0) | 2022.10.30 |
c언어 stack (0) | 2022.10.29 |
double link (0) | 2022.10.28 |