Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d19c83c

Browse files
Merge pull request #73 from ManasviGoyal/dsa
added palindrome deque in dsa
2 parents eed08d1 + 9ebc910 commit d19c83c

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

‎DSA/pallindrome_deque.cpp‎

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Find if a string is palindrome or not using DeQue
2+
#include<iostream>
3+
using namespace std;
4+
5+
#define MAX 100
6+
7+
int size, Q[MAX], front=-1, rear=-1, x;
8+
9+
void insert_rear(int x)
10+
{
11+
if(front==-1)
12+
front=0;
13+
rear++;
14+
Q[rear]=x;
15+
}
16+
17+
int delete_from_front()
18+
{
19+
if(front==-1)
20+
cout<<"DeQueue is Empty\n";
21+
if (front==rear)
22+
{
23+
int d=Q[front];
24+
front=rear=-1;
25+
return d;
26+
}
27+
28+
else if (front==size-1)
29+
{
30+
int d=Q[front];
31+
front=0;
32+
return d;
33+
}
34+
else
35+
{
36+
int d=Q[front];
37+
front=front+1;
38+
return d;
39+
}
40+
}
41+
42+
int delete_from_rear() {
43+
if(front==-1)
44+
cout<<"DeQueue is Empty\n";
45+
if (front==rear)
46+
{
47+
int d=Q[rear];
48+
front=rear=-1;
49+
return d;
50+
}
51+
else if (rear==0)
52+
{
53+
int d=Q[rear];
54+
rear=size-1;
55+
return d;
56+
57+
}
58+
else
59+
{
60+
int d=Q[rear];
61+
rear=rear-1;
62+
return d;
63+
}
64+
}
65+
66+
int main()
67+
{
68+
int c,a,b,flag=0,cnt=0;
69+
char ele[MAX];
70+
cout<<"Enter the string: ";
71+
gets(ele);
72+
for(int j=0; ele[j] != '0円'; j++)
73+
{
74+
cnt++;
75+
}
76+
size=cnt;
77+
int count=size/2;
78+
for (int i=0;i<size;i++)
79+
{
80+
insert_rear(ele[i]);
81+
}
82+
while(count>0)
83+
{
84+
a=delete_from_front();
85+
b=delete_from_rear();
86+
if(a!=b)
87+
flag=1;
88+
count--;
89+
}
90+
if(flag==0)
91+
cout<<"\nString is a Pallindrome\n";
92+
else
93+
cout<<"\nString is not a Pallindrome\n";
94+
return 0;
95+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /