-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
49 lines (43 loc) · 762 Bytes
/
stack.cpp
File metadata and controls
49 lines (43 loc) · 762 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
#include <iostream>
#include "Stack.h"
//lab1
Stack::Stack(
top=-1;
)
bool Stack::isFull(){return MAX_STACK_SIZE-1;}
bool Stack::isEmpty(){return top<0;}
Stack::~Stack(){}
void Stack::push(int element)
{
if(top >=MAX_STACK_SIZE - 1)//(isFull=1)
{
std::cout<<"Cannot push"<<element<<".Stack is full";
}
else
{
top++;
this->elements[top]=element;
}
}
int Stack::pop()
{
if(top<0)//(isEmpty=1)
{
std::cout<<"Cannot pop an element from an empty stack."<<
}
else
{
//remove and return this ->elements[top];top--;
return elements[top--];
}
}
int Stack::top(){cout<<element[top];}
int main()
{
Stack s;
s.push(3);
s.push(4);
s.push(22);
s.pop();
s.top();
}