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
Select all the correct answers
ikadub [295]
Umm I think 3 and 1
5 0
3 years ago
The Windows taskbar is generally found _____. at the top of the screen in the Start menu at the bottom of the screen at the righ
rjkz [21]
At the bottom of the screen.
4 0
3 years ago
Read 2 more answers
Repeated execution of a set of programming statements is called repetitive execution.
Korolek [52]

Answer:

False

Explanation:

6 0
2 years ago
Your friend sends you a computer game. after installing the game on your computer, you realize that it plays very slowly. you kn
dsp73
Memory possibly. Or another pricessor.
8 0
3 years ago
Write down the stages in the information prcessing cycle in correct order​
Naddika [18.5K]

Answer:

The answer is below

Explanation:

The various stages in the information processing cycle in the correct order​ is as follows:

1. Input stage: this is when the data is sent into the computer through the hardware

2. Processing stage: this when the is being refined in the central processing unit of the computer

3. Storage stage: this is when the data is being saved or stored in the computer memory such as Hard drive or external storage such as Flash drive

4. Output stage: this is when the refined or processed data is produced to the user either through the monitor screen or printing

4 0
3 years ago
Other questions:
  • HELP PLEASE
    7·2 answers
  • You can use ???? a to test tread wear on your tires
    14·2 answers
  • The ____ category of apps makes the computer easier for blind people to use.
    9·1 answer
  • Create a structure named planet This structure will contain distance from Earth as an integer Atmosphere, language, people and p
    8·1 answer
  • In the beginning of a presentation, it is important to:
    9·1 answer
  • What is the name for the type of flash memory that is used by mobile devices to store their apps and data?
    6·1 answer
  • Do people answer questions more on this site or be on social more ??? no right or wrong answer your opinion
    6·1 answer
  • Three types of query​
    13·1 answer
  • What kind of AR target category makes sense for a playing card with a picture on it?
    12·1 answer
  • Why does python code generate fewer types of syntax errors than code in other programming languages?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!