1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
V125BC [204]
3 years ago
5

Write a program that reads a string of characters, pushing each character onto a stack as it is read and simultaneously adding i

t to a queue. When the end of the string is encountered the program should use basic stack and queue operations to determine if the word is a palindrome.
Computers and Technology
1 answer:
sleet_krkn [62]3 years ago
4 0

Answer:

#include <iostream>

#include <stack>

#include <queue>

#include <string>

int main()

{

   while ( true )

   {

       std::string letters;

       std::cout << "Please enter a word (Enter - exit): ";

       std::getline( std::cin, letters );

       if ( letters.empty() ) break;

       std::stack<char>

           s( std::stack<char>::container_type( letters.begin(), letters.end() ) );

       std::queue<char>

           q( std::queue<char>::container_type( letters.begin(), letters.end() ) );

       while ( !s.empty() && s.top() == q.front() )

       {

           s.pop();

           q.pop();

       }

if ( s.empty() ) std::cout << "The word is a palindrome" << std::endl;

       else std::cout << "The word is not a palindrome" << std::endl;

   }

   return 0;

}

Explanation:

A <em>stack</em> is used to replicate a stack data structure in C++  while <em>Queue </em>container is a replica of the queue data structure in C++, Unlike stack, in the queue container, there are two ends, i.e. front, and back.

In the code above to be able to use used stack and queue, we included the headers #include <stack> and#include <queue>.

You might be interested in
What cell phone technology is the most popular in the united states?
Alchen [17]
IPhone and Android. ....
3 0
3 years ago
Read 2 more answers
What Is The First Computer Brought In Nepal ? <br>​
tiny-mole [99]

Answer:

I don't know,,,(((:lol

8 0
2 years ago
Blood Alcohol Level (BAL) is the ratio between the alcohol consumed and the blood in the body. A. True B. False
horsena [70]
I think its true I'm not sure
3 0
3 years ago
Read 2 more answers
If someone you don’t know asks where you go to school, what should you do
My name is Ann [436]

Answer:

Don't answer him because you don't know what he is going to do

8 0
3 years ago
PLZ ANSWER ALL MY QUESTION. Which line of code will display the variable num rounded to the nearest tenth?
zavuch27 [327]

Answer:

A

Explanation:

5 0
3 years ago
Other questions:
  • Which subject area describes collecting and analyzing data from computer systems, networks, and storage devices, as part of an i
    7·1 answer
  • Write a for loop to verify that your function is correctly returning the expected output for the radius values between 0 and 11.
    14·1 answer
  • An interface is a class that contains only the method headings and each method heading is terminated with a semicolon. True Fals
    7·1 answer
  • Boardman College maintains two files—one for Sociology majors and another for Anthropology majors. Each file contains students'
    5·1 answer
  • i set up an account and paid the yearly fee, now it's asking me to join. i've tried to log in and brainly isn't accepting my ema
    8·1 answer
  • Given two variables, is Empty of type boolean, indicating whether a class roster is empty or not, and number Of Credits of type
    10·1 answer
  • The design of a blog refers to:
    10·1 answer
  • Resize vector countDown to have newSize elements. Populate the vector with integers {newSize, newSize - 1, ..., 1}. Ex: If newSi
    6·1 answer
  • WHAT ARE SOME PROS AND CONS OF HYDROGEN FUELL CELLS
    11·1 answer
  • A) Calculate the checksum of following 2 bytes: 00110101 and 10101100, and fill in the blank:
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!