-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_stream_panlindrome.cpp
62 lines (62 loc) · 1.05 KB
/
_stream_panlindrome.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
#include<iostream>
using namespace std;
void check_palindrome(char);
struct node {
node *prev;
node *next;
char val;
}*head,*tail;
void insert(char c){
if (head==NULL) {
head = new node;
head->val = c;
tail=head;
}
else{
node *newtail = new node;
newtail->val = c;
tail->next = newtail;
newtail->prev = tail;
tail=newtail;
}
}
void printfwd() {
cout<< "\n Printing FWD:";
struct node *i = head;
while (i!=NULL) {
cout<< "-" << i->val;
i=i->next;
}
}
void printback () {
cout<< "\n Printing BWD:";
struct node *i = tail;
while (i!=NULL) {
cout<< "-" << i->val;
i=i->prev;
}
}
int main() {
string stream = "ababa";
for (int count=0; count<=stream.length();count++) {
//cout<<"\n"<<stream.substr(0,i);
int pal=0;
node *i=head;
node *j=tail;
insert(stream[count]);
//printfwd();
while (i!=j) {
if (i->val!=j->val){
pal=1;
break;
}
i=i->next;
j=j->prev;
}
if (pal ==1) {
cout<<"\nNot a palindrome:"<< stream.substr(0,count);
}else{
cout<<"\nA palindrome:"<< stream.substr(0,count) ;
}
}
}