-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_using_array.cpp
More file actions
57 lines (45 loc) · 1013 Bytes
/
stack_using_array.cpp
File metadata and controls
57 lines (45 loc) · 1013 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
54
55
56
57
#include <iostream>
using namespace std;
//implementing stack using arrays
template<class T>
class stack{
private:
int length;
int top;
T* arr;
public:
stack(){
top = -1;
lenght = 0;
arr = new T[100];
}
void push(T data){
if(top ==99){
cout<<"stack is full"<<"\n";
return;
}
arr[++top] = data;
length++;
}
T pop(){
if(top == -1){
cout<<"stack is empty"<<"\n";
return NULL;
}
length--;
return arr[top--];
}
T getTop(){
if(top == -1){
cout<<"stack is empty"<<"\n";
return NULL;
}
return arr[top];
}
int size(){
return length;
}
};
int main(){
return 0;
}