-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackStringPal.cpp
More file actions
61 lines (61 loc) · 958 Bytes
/
stackStringPal.cpp
File metadata and controls
61 lines (61 loc) · 958 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
50
51
52
53
54
55
56
57
58
59
60
61
#include<iostream>
#include<string>
using namespace std;
struct str
{
char *data;
int top;
str(int s)
{
data = new char[s];
}
};
int getLength(char s[])
{
int i=0;
while(s[i]!='\0')
{
i++;
}
return i;
}
str *p;
void init()
{
p->top=-1;
}
void strpal(char s[],int len)
{
int i=0;
int ispal=1;
while(i<len&&p->top!=-1)
{
if(p->data[p->top--]!=s[i])
{ispal=0;
break;}
i++;
}
if(ispal)
cout<<s<<" is palindrome string";
else
cout<<s<<" is not palindrome string";
}
int main()
{
char word[100];
cout<<"enter a word: ";
fgets(word,100,stdin);
int len=getLength(word);
if (word[len - 1] == '\n')
{
word[len - 1] = '\0';
len--;
}
p=new str(len);
init();
//pushing char into stack
for(int i=0;i<len;i++)
p->data[++p->top]=word[i];
strpal(word,len);
delete p;
}