-
Notifications
You must be signed in to change notification settings - Fork 59
Expand file tree
/
Copy pathstack.cpp
More file actions
55 lines (52 loc) · 946 Bytes
/
stack.cpp
File metadata and controls
55 lines (52 loc) · 946 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
#pragma once
#include <iostream>
using namespace std;
#define N 10
class StackArray
{
private:
//Declaring an array with top pointer to point on the top of stack
int A[N], top;
public:
//Initializing the top with in constructor
StackArray() {
top = 0;
}
//creating a check method to check if stack is full or not
bool isFull() {
if (top == N)
return true;
return false;
}
//creating the check method to check if stack is empty or not
bool isEmpty() {
if (top == 0)
return true;
return false;
}
//method to push in the stack
bool push(int y) {
if (isFull())
return false;
A[top] = y;
top++;
return true;
}
//method to pop from the stack
int pop() {
if (!isEmpty()) {
top--;
int x = A[top];
return true;
}
return false;
}
//Method to print the whole stack
bool print() {
if (isEmpty())
return false;
for (int i = 0; i < top; i++)
cout << A[i] << " ,";
return true;
}
};