-
Notifications
You must be signed in to change notification settings - Fork 0
/
Practice Doubly - Stack - PALINDROME.cpp
81 lines (66 loc) · 1.16 KB
/
Practice Doubly - Stack - PALINDROME.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//Practice Doubly Linked List
//Created by: Charlene Diana Schenk
//DoublyLinkedList Stack - PALINDROME
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
struct nodeType{
char data;
struct nodeType *next;
struct nodeType *prev;
} *head,*newNode,*myList,*current,*top;
void Push(char e){
newNode=new nodeType;
newNode->data=e;
newNode->prev=top;
newNode->next=NULL;
top->next=newNode;
top=newNode;
};
char Pop(){
char e=top->data;
top=top->prev;
return e;
};
char Top(){
char e=top->data;
return e;
};
int main(){
myList=new nodeType;
head=myList;
top=head;
char palindrome[1000];
cout<<"Input a word, phrase or sentence: ";
cin.getline(palindrome,1000);
int i=0,size=0;
char temp[1000];
while(palindrome[i]!='\0'){
if(palindrome[i]!=' '){
temp[size]=tolower(palindrome[i]);
size++;
}
i++;
}
for(i=0;i<=size/2-1;i++)
Push(temp[i]);
if(size%2==1)
i++;
bool palindrometf=true;
while(i<size){
if(Pop()!=temp[i]){
palindrometf=false;
break;
}
i++;
}
if(palindrometf)
cout<<"IS a palindrome!";
else
cout<<"IS NOT a palindrome!";
getch();
return 0;
}