From a436f3acf3135bf1aa9e752d69563f5ef3dbe97d Mon Sep 17 00:00:00 2001 From: Manasvi Goyal <55101825+ManasviGoyal@users.noreply.github.com> Date: Wed, 29 Sep 2021 15:04:31 +0530 Subject: [PATCH 1/2] added palindrome_deque Find if a string is palindrome or not using DeQue --- DSA/pallindrome_deque.cpp | 94 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 DSA/pallindrome_deque.cpp diff --git a/DSA/pallindrome_deque.cpp b/DSA/pallindrome_deque.cpp new file mode 100644 index 00000000..2ddaeeef --- /dev/null +++ b/DSA/pallindrome_deque.cpp @@ -0,0 +1,94 @@ +#include +using namespace std; + +#define MAX 100 + +int size, Q[MAX], front=-1, rear=-1, x; + +void insert_rear(int x) +{ + if(front==-1) + front=0; + rear++; + Q[rear]=x; +} + +int delete_from_front() +{ + if(front==-1) + cout<<"DeQueue is Empty\n"; + if (front==rear) + { + int d=Q[front]; + front=rear=-1; + return d; + } + + else if (front==size-1) + { + int d=Q[front]; + front=0; + return d; + } + else + { + int d=Q[front]; + front=front+1; + return d; + } +} + +int delete_from_rear() { + if(front==-1) + cout<<"DeQueue is Empty\n"; + if (front==rear) + { + int d=Q[rear]; + front=rear=-1; + return d; + } + else if (rear==0) + { + int d=Q[rear]; + rear=size-1; + return d; + + } + else + { + int d=Q[rear]; + rear=rear-1; + return d; + } +} + +int main() +{ + int c,a,b,flag=0,cnt=0; + char ele[MAX]; + cout<<"Enter the string: "; + gets(ele); + for(int j=0; ele[j] != '\0'; j++) + { + cnt++; + } + size=cnt; + int count=size/2; + for (int i=0;i0) + { + a=delete_from_front(); + b=delete_from_rear(); + if(a!=b) + flag=1; + count--; + } + if(flag==0) + cout<<"\nString is a Pallindrome\n"; + else + cout<<"\nString is not a Pallindrome\n"; + return 0; +} From 9ebc910d66fa3517299a9384a4589fa38e3675c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=2E=20=C3=85nand?= <73425223+Astrodevil@users.noreply.github.com> Date: Fri, 1 Oct 2021 01:56:42 +0530 Subject: [PATCH 2/2] Update pallindrome_deque.cpp --- DSA/pallindrome_deque.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/DSA/pallindrome_deque.cpp b/DSA/pallindrome_deque.cpp index 2ddaeeef..bf37907e 100644 --- a/DSA/pallindrome_deque.cpp +++ b/DSA/pallindrome_deque.cpp @@ -1,3 +1,4 @@ +// Find if a string is palindrome or not using DeQue #include using namespace std;