-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack.cpp
56 lines (56 loc) · 896 Bytes
/
Stack.cpp
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
#include<iostream>
#include"Headers/LinkedList.h"
#include"Headers/Stack.h"
using namespace std;
void Stack_A::create(int n)
{
Stack_A::element=new int [n];
capacity=n;
}
bool Stack_A::Is_Full()
{
return head==capacity-1;
}
bool Stack_A::Is_Empty()
{
return head==-1;
}
void Stack_A::push(int a)
{
if(!Is_Full()){
element[++head]=a;
}else{
cout<<"stack is full\n";
}
}
int Stack_A::pop()
{
if(!Is_Empty())
return element[head--];
}
int Stack_A::peek()
{
return element[head];
}
bool Stack_L::Is_Empty(){
return head==NULL;
}
void Stack_L::push(int a)
{
Node *x=new Node;
x->value=a;
x->next=head;
head=x;
}
int Stack_L::pop()
{
if(!Is_Empty()){
int a=head->value;
delete head;
head=head->next;
return a;}
}
int Stack_L::peek()
{
return head->value;
}