-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStackList.cpp
66 lines (66 loc) · 985 Bytes
/
StackList.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
57
58
59
60
61
62
63
64
65
66
#include"SLL.cpp"
class stack:private SLL{
public:
stack();
void push(int);
void pop();
int peek();
void reverse(stack &);
bool empty();
void operator=(stack &);
bool Palindrome(int);
};
bool stack::Palindrome(int number)
{int i,count=0;
for(i=number;i>0;i/=10){count++;}
stack Aux;
i=number;
while(i)
{
Aux.push(i%10);
i=i/10;
}
while(number)
{
if(number%10==Aux.peek()){
Aux.pop();
number=number/10;
}
else{
return false;
}
}
return true;
}
void stack::operator=(stack &s2)
{
SLL::operator=(s2);
}
bool stack::empty(){
node* ptr=get_start();
if(get_start()!=NULL){
return false;
}
else{
return true;
}
}
void stack::reverse(stack &s1){
stack temp;
while(!s1.empty())
{
temp.push(s1.peek());
s1.pop();
}
s1=temp;
}
int stack::peek(){
return (get_start())->data;
}
void stack::push(int data){
In_Beginnings(data);
}
void stack::pop(){
del_Beginnings();
}
stack::stack():SLL(){}