-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPalindrome.cpp
More file actions
88 lines (88 loc) · 1.28 KB
/
Copy pathPalindrome.cpp
File metadata and controls
88 lines (88 loc) · 1.28 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
77
78
79
80
81
82
83
84
85
86
87
88
#include<iostream>
#include<string.h>
#define max 50
using namespace std;
class STACK
{
private:
char a[max];
int top;
public:
STACK()
{
top=-1;
}
void push(char);
void reverse();
void convert(char[]);
void palindrome();
};
void STACK::push(char c)
{
top++;
a[top] = c;
a[top+1]='\0';
cout<<endl<<c<<" is pushed on stack";
}
void STACK::reverse()
{
char str[max];
cout<<"\n\nReverse string is : ";
for(int i=top,j=0; i>=0; i--,j++)
{
cout<<a[i];
str[j]=a[i];
}
cout<<endl;
}
void STACK::convert(char str[])
{
int j,k,len = strlen(str);
for(j=0, k=0; j<len; j++)
{
if( ( (int)str[j] >= 97 && (int)str[j] <=122 ) || ( (int)str[j] >= 65 && (int)str[j] <=90 ))
{
if( (int)str[j] <=90 )
{
str[k] = (char)( (int)str[j] + 32 );
}
else
{
str[k] = str[j];
}
k++;
}
}
str[k]='\0';
cout<<endl<<"Converted String : "<<str<<"\n";
}
void STACK::palindrome()
{
char str[max];
int i,j;
for(i=top,j=0; i>=0; i--,j++)
{
str[j]=a[i];
}
str[j]='\0';
if(strcmp(str,a) == 0)
cout<<"\n\nString is palindrome";
else
cout<<"\n\nString is not palindrome";
}
int main()
{
STACK stack;
char str[max];
int i=0;
cout<<"\nEnter string to be reversed and check is it palindrome or not : \n\n";
cin.getline(str , 50);
stack.convert(str);
while(str[i] != '\0')
{
stack.push(str[i]);
i++;
}
stack.palindrome();
stack.reverse();
}