-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLab6_Q1.cpp
More file actions
76 lines (73 loc) · 1.06 KB
/
Lab6_Q1.cpp
File metadata and controls
76 lines (73 loc) · 1.06 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
64
65
66
67
68
69
70
71
72
73
74
75
76
#include<iostream>
#include<cstring>
using namespace std;
class stack {
private:
int top;
int size;
char *arr;
public:
stack(int s) {
size=s;
arr=new char[size];
top=-1;
}
void push(char val) {
if(top<size-1) {
top++;
arr[top]=val;
} else {
cout<<"stack is full"<<endl;
}
}
void pop() {
if(top!=-1) {
top--;
} else {
cout<<"stack is empty"<<endl;
}
}
bool isempty() {
if(top==-1) {
return true;
}
return false;
}
bool isfull() {
if(top==size-1) {
return true;
}
return false;
}
char gettop() {
if(top!=-1) {
return arr[top];
}else{
return '\0';
}
}
~stack(){
delete[]arr;
}
};
bool ispalindrome(string name) {
stack s(name.size());
for(int i=0; name[i]!='\0'; i++) {
s.push(name[i]);
}
for(int i=0; i<name.size(); i++) {
if(name[i]!=s.gettop()) {
return false;
}
s.pop();
}
return true;
}
int main(){
string name="BORROWROB";
if(ispalindrome(name)) {
cout<<"It is palindrome"<<endl;
} else {
cout<<"It is not a palindrome"<<endl;
}
}