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 58 59 | #include<iostream> using namespace std; struct Node { int data; Node* next; }*top=NULL; void push(int x) { Node* t; t = new Node; if (t == NULL) cout << "stack is full"; else { t->data = x; t->next = top; top = t; } } int pop() { Node* t; int x = -1; if (top == NULL) cout << "empty"; else { t = top; top = top->next; x = t->data; delete t; } return x; } void Display() { Node* p; p = top; while (p) { cout << p->data<< " "; p = p->next; } } int main() { push(10); push(20); push(30); pop(); Display(); return 0; } | cs |
'알고리즘' 카테고리의 다른 글
Link stack C++ (0) | 2022.10.30 |
---|---|
ADT stack (0) | 2022.10.30 |
double link (0) | 2022.10.28 |
싸이클 리스트 (0) | 2022.10.28 |
list C++ (0) | 2022.10.28 |