-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_LinkedList.cpp
More file actions
63 lines (54 loc) · 1.02 KB
/
stack_LinkedList.cpp
File metadata and controls
63 lines (54 loc) · 1.02 KB
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
60
61
62
63
#include <iostream>
using namespace std;
template<class T>
class Node{
private:
int data;
Node* next;
};
template<class T>
class stack{
private:
int length;
Node<T>* top;
public:
stack(){
length = 0;
top = NULL;
}
void push(T data){
Node<T>* ptr= new Node<T>(data);
if(top==NULL){
top=ptr;
}else{
ptr->next = top;
top = ptr;
}
lenght++;
}
T getTop(){
if(top==-1){
cout<<"stack is empty";
}else{
return top->data;
}
}
T pop(){
if(top==NULL){
cout<<"your stack is empty\n";
return NULL;
}
Node<T>* deleted = top;
top = top->next;
T deletedData = deleted->data;
deleted(deleted);
length--;
return deletedData;
}
int size(){
return lenght;
}
};
int main(){
return 0;
}