-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignment-7.cpp
More file actions
153 lines (145 loc) · 2.27 KB
/
Copy pathassignment-7.cpp
File metadata and controls
153 lines (145 loc) · 2.27 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include<iostream>
#include<string.h>
using namespace std;
class chain;
class node
{
char data;
node *link;
friend class chain;
};
class chain
{
node *start=NULL;
public:
void push(char ch)
{
node *q=start;
node *temp= new node;
temp->data=ch;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
temp->link=start;
start=temp;
}
}
void add_node(char num)
{
node *q=start;
node *temp= new node;
temp->data=num;
temp->link=NULL;
if(start==NULL)
{
start=temp;
}
else
{
while(q->link!=NULL)
{
q=q->link;
}
q->link=temp;
}
}
void display()
{
node *q=start;
if(start==NULL)
{
cout<<"List is empty.\n";
}
else
{
while(q!=NULL)
{
cout<<q->data;
q=q->link;
}
}
}
int compare(chain list)
{
node *q=start;
node *p=list.start;
while(q!=NULL)
{
if(q->data!=p->data)
{
return 1;
}
q=q->link;
p=p->link;
}
return 0;
}
};
int main()
{
int n,i,k,choice,num;
chain list1,list2,list3;
char input[50];
do
{
cout<<"Enter your choice\n1. Input string\n2. Display\n3. To find palindrome or not\n4. Display reversed string\n 5. Exit\n";
cin>>choice;
switch (choice)
{
case 1: {cout<<"Enter string input : ";
cin.get();
cin.getline(input,50);
n=strlen(input);
cout<<"You entered string : ";
for(i=0;i<n;i++)
{
list3.push(input[i]);
cout<<input[i];
}
cout<<endl;}
break;
case 2: cout<<"You entered string : ";
for(i=0;i<n;i++)
{
cout<<input[i];
}
cout<<endl;
break;
case 3: for(i=0;i<n;i++)
{
if((input[i]>='A' && input[i]<='Z') || (input[i]>='a' && input[i]<='z'))
{
if(input[i]>='A' && input[i]<='Z')
{
list1.push(input[i]+32);
list2.add_node(input[i]+32);
}
else
{
list1.push(input[i]);
list2.add_node(input[i]);
}
}
}
k=list1.compare(list2);
if(k==0)
{
cout<<"The input string is palindrome\n";
}
else if(k==1)
{
cout<<"The list is not a palindrome\n";
}
break;
case 4: cout<<"Reversed string is : ";
list3.display();
cout<<endl;
break;
}
}while(choice!=5);
return 0;
}