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
Chances are if you ar Chances are, if you are involved in a crash, it will happen __________ a. during a long trip. b. close to
JulijaS [17]
During a long trip. Hope this helps!
6 0
3 years ago
Read 2 more answers
Trish uas bought a new computer, which she plans to start working on aftwr a week. Since Trish has not used computers in the pas
stepladder [879]

The answer would be B. She should minimize the use of the computer. Hope this helps! :)


<h3>CloutAnswers</h3>
6 0
3 years ago
Key Categories: more libraries and thousands of functions
Vadim26 [7]

Answer:

2b2t

Explanation:

2b2t

6 0
4 years ago
The ________ of the operating system enables the user to communicate with the computer system. Select one:
mojhsa [17]
The user interface (correct answer is a)
8 0
3 years ago
Orphan record example?
Goryan [66]

Answer:

If we delete record number 15 in a primary table, but there's still a related table with the value of 15, we end up with an orphaned record. Here, the related table contains a foreign key value that doesn't exist in the primary key field of the primary table. This has resulted in an “orphaned record”.

4 0
3 years ago
Other questions:
  • What does a company’s code of ethics cover
    8·2 answers
  • The number of credits awarded for the CLEP exam is determined by__<br> Help pls!
    15·1 answer
  • What are 3 characteristics of syndrome E?
    13·1 answer
  • Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if appropriate. Granite Sales C
    12·1 answer
  • Carly is part of a community of developers. In her free time, she works on code to improve this open-source operating system. Th
    11·1 answer
  • pWhat macOS system application tracks each block on a volume to determine which blocks are in use and which ones are available t
    14·1 answer
  • ________ is the standard communications protocol used on most client/server networks.
    9·1 answer
  • To display data in a certain manner, like alphabetical order, is called
    5·2 answers
  • Which of the following is the path to the Zoom button?
    8·1 answer
  • How does the variable scope influence the structure of an algorithm
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!