This repository was archived by the owner on Jun 2, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +90
-2
lines changed
C++/Data Structure/Stacks Expand file tree Collapse file tree 3 files changed +90
-2
lines changed Original file line number Diff line number Diff line change @@ -21,4 +21,4 @@ time complexity -
21
21
"""
22
22
```
23
23
24
- Become a maintainer on this repo - https://discord.gg/D4YmRxY
24
+ ### README - [ How to Contribute ] ( https://github.com/Py-Contributors/AlgorithmsAndDataStructure/blob/master/CONTRIBUTING.md )
Original file line number Diff line number Diff line change
1
+ // C++ Program to implement Stack Data Structure
2
+ #include < bits/stdc++.h>
3
+ // Setting a Max SIZE for Stack
4
+ #define SIZE 100
5
+
6
+ using namespace std ;
7
+
8
+ class Stack
9
+ {
10
+ int item[SIZE];
11
+ int top;
12
+
13
+ public:
14
+ Stack () // default constructor
15
+ {
16
+ top = -1 ;
17
+ }
18
+
19
+ bool isEmpty () // check if stack is Empty
20
+ {
21
+ if (top == -1 )
22
+ {
23
+ cout << " Stack is Empty\n " ;
24
+ return true ;
25
+ }
26
+ return false ;
27
+ }
28
+
29
+ bool isFull () // check if stack in Full
30
+ {
31
+ if (top == SIZE - 1 )
32
+ {
33
+ cout << " Stack is full\n " ;
34
+ return true ;
35
+ }
36
+ return false ;
37
+ }
38
+
39
+ void push (int val) // push elements into the stack
40
+ {
41
+ if (isFull ())
42
+ {
43
+ exit (0 );
44
+ }
45
+ top++;
46
+ item[top] = val;
47
+ }
48
+
49
+ int pop () // pop elements from the stack
50
+ {
51
+ int val;
52
+ if (isEmpty ())
53
+ {
54
+ exit (0 );
55
+ }
56
+ val = item[top];
57
+ top--;
58
+ return val;
59
+ }
60
+
61
+ int peek () // return element at the top of stack
62
+ {
63
+ int val;
64
+ if (isEmpty ())
65
+ {
66
+ exit (0 );
67
+ }
68
+ val = item[top];
69
+ return val;
70
+ }
71
+ };
72
+
73
+ int main ()
74
+ {
75
+ Stack s;
76
+ s.push (10 );
77
+ s.push (30 );
78
+ s.push (20 );
79
+ s.push (5 );
80
+ s.push (1 );
81
+ cout << s.pop () << endl;
82
+ cout << s.pop () << endl;
83
+ cout << s.peek () << endl;
84
+ cout << s.pop () << endl;
85
+ cout << s.pop () << endl;
86
+ cout << s.pop () << endl;
87
+ return 0 ;
88
+ }
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ Check [Contribution](/CONTRIBUTING.md) Guide Before Contribution.
46
46
| ---------------- | ---------------- | ----------------- | -------------------- |
47
47
| Linked List | Yes | Yes | Being improved #23 |
48
48
| Sets | Yes | Yes | Implemented |
49
- | Stack | No | In progress #13 | |
49
+ | Stack | Yes | In progress #13 | |
50
50
| Queue | In progress #7 | In progress #12 | |
51
51
52
52
You can’t perform that action at this time.
0 commit comments