-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDouble_palin.cpp
More file actions
79 lines (78 loc) · 1.37 KB
/
Double_palin.cpp
File metadata and controls
79 lines (78 loc) · 1.37 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
#include<iostream>
using namespace std;
struct node
{
char data;
node *prev,*next;
};
typedef node* NODE;
NODE get_node()
{
NODE x;
x=new node;
if(x==NULL)
cout<<"Memory Full";
return x;
}
NODE insert_front(NODE &head,char x)
{
NODE temp=get_node();
temp->data=x;
temp->next=NULL;
temp->prev=NULL;
if(head==NULL)
{
head=temp;
return head;
}
temp->next=head;
head=temp;
return head;
}
void display(NODE head)
{
NODE temp=head;
cout<<"\nList : ";
while(temp!=NULL)
{
cout<<temp->data<<"->";
temp=temp->next;
}
cout<<endl;
}
NODE make_string_list(NODE &head,char a[])
{
for(int i=0;a[i]!='\0';i++)
head=insert_front(head,a[i]);
return head;
}
int palin(NODE &head)
{
NODE temp1=head,temp2=head;
while(temp2->next!=NULL)
temp2=temp2->next;
while(temp1!=NULL&&temp2!=NULL)
{
if(temp1->data!=temp2->data)
return false;
temp1=temp1->next;
temp2=temp2->prev;
}
return true;
}
int main()
{
NODE head=NULL;
int x;
cout<<"Enter length of string : ";
cin>>x;
char a[x];
cout<<"Enter the string : ";
cin>>a;
head=make_string_list(head,a);
if(palin(head))
cout<<"\nString is palindrome ";
else
cout<<"\nString is NOT palindrome";
return 0;
}