Skip to content
This repository was archived by the owner on Jun 2, 2024. It is now read-only.

Commit f653869

Browse files
authored
Merge pull request #1 from Py-Contributors/master
Merge request
2 parents 8de1107 + cfdc176 commit f653869

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ time complexity -
2121
"""
2222
```
2323

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)

C++/Data Structure/Stacks/stackds.cpp

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Check [Contribution](/CONTRIBUTING.md) Guide Before Contribution.
4646
|---------------- |---------------- |----------------- |-------------------- |
4747
| Linked List | Yes | Yes | Being improved #23 |
4848
| Sets | Yes | Yes | Implemented |
49-
| Stack | No | In progress #13 | |
49+
| Stack | Yes | In progress #13 | |
5050
| Queue | In progress #7 | In progress #12 | |
5151

5252

0 commit comments

Comments
 (0)