Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a program to read a line of text and tell us if the line is a palindrome.

ID: 3564298 • Letter: C

Question

Create a program to read a line of text and tell us if the line is a palindrome. Do this by using a stack data structure and a queue data structure. The program should be using these STL: string class, stack class, queue class and Iterators.

Program should look something like this.

Create a program to read a line of text and tell us if the line is a palindrome. Do this by using a stack data structure and a queue data structure. The program should be using these STL: string class, stack class, queue class and Iterators. Program should look something like this.

Explanation / Answer

# include "palindrome3.h"

# include <iostream.h>

void blankspace(char *s, char *t)

{while (*s!=NULL)

{if (*s!=' ')

*t=*s;t++

s++;

}

*t=NULL; //append NULL to newstring

}

  

void main ()

{const int True=1, False=0;

// create stack object to store string in reverse order.

Stack S;

char palstring[ 80] , blankspacestring[ 80] , c;

int i=0; // string pointer

int ispalindrome=True; //we'll stop if false

// get input

cin. Getline(palstring,80,' ');

//remove blanks

blankspace(palstring,blankspacestring);// A[],the array;A pointer to A[]

//push character onto stack

i=0;

while(blankedspacestring[i] !=NULL)

{

S.Push(blankspacestring[i] );

i++;

}

//now pop one-by-one comparing with original

i=0;

while (!S.StackEmpty())

{

c=S.Pop();

//get out of loop when first nonmatch

if (c!=blankspacestring[i])

{isPalindrome=False;

break;

}

// continue till end of string

i++;

}

//operation finished. Printout result

if (ispalindrome)

cout<<""<<palstring<<""<<"is a palindrome<<endl;

else

cout<<""<<palstring<<""<<"is not a palindrome<<endl;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote