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
When selecting a color scheme for a project which two things should you consider?
Vsevolod [243]

colorfulness and depending on your teacher pick colors that will go together on the project

6 0
3 years ago
A network of Bennetton retail sales agents select the Bennetton designs that they feel will appeal to Bennetton retail customers
denpristay [2]

Answer:

It is an example of a matrix structure

Explanation:

The matrix structure is a structure in which jurisdiction, controls and duties are carried and uphold by a group of employees instead of just the manager.

In other words, employees have dual reporting relationships; they can give reports to the functional manager and they can also give reports to the product manager.

The Bennetton design selected by the network of Bennetton retail sales agents made activities to be easily coordinated because, they have collectively performed the duty as a unit and this is one of the advantages of this form of the matrix organizational structure.

7 0
3 years ago
Read 2 more answers
What is output by the following code?
Naily [24]

Answer:

Sum = 3

Sum = 9

Sum = 18

Sum = 30

Look at the image for more information.

4 0
2 years ago
Write a program in c++ to read two integers, calculate and print the smallest
Shalnov [3]

Answer:

#include<iostream>

using namespace std;

int main (){

int n1, n2;

cout<<"Enter 1st number";

cin>>n1;

cout<<"Enter 2nd number";

cin>>n2;

if(n1<n2){

cout<<"The 1st number is the smallest"<<endl<<" is= "<<n1;

}

else{

cout<<"The 2nd number is the smallest"<<endl<<" is= "<<n2;

}

}

return 0;

3 0
3 years ago
5. Write few lines of code that creates two arrays with malloc. Then write a statement that can create a memory leak. Discuss wh
Darina [25.2K]

Answer:

 // function with memory leak  

void func_to_show_mem_leak()  {  

int *pointer;

pointer = malloc(10 * sizeof(int));

*(pointer+3) = 99;}  

 

// driver code  

int main()  

{  

    // Call the function  

   // to get the memory leak  

   func_to_show_mem_leak();  

     return 0;  }

Explanation:

Memory leakage occurs when programmers allocates memory by using new keyword and forgets to deallocate the memory by using delete() function or delete[] operator. One of the most memory leakage occurs by using wrong delete operator. The delete operator should be used to free a single allocated memory space, whereas the delete [] operator should be used to free an array of data values.

3 0
2 years ago
Other questions:
  • What does OLE stand for? Object
    8·2 answers
  • It takes 2 seconds to read or write one block from/to disk and it also takes 1 second of CPU time to merge one block of records.
    10·1 answer
  • ________is a Windows software program with powerful accessibility solution that reads information on your screen using synthesiz
    9·1 answer
  • A network protocol is a set of rules defining communication between two devices. True False
    8·2 answers
  • Which of the following is not true about designing classes? In order for class information to be printed instead of a memory add
    12·1 answer
  • Which is the correct sequence of steps for opening a new document?
    10·2 answers
  • You are interested in buying a laptop computer. Your list of considerations include the computer's speed in processing data, its
    11·1 answer
  • ISO 400 is twice as sensitive and ISO 100 true or false
    7·1 answer
  • 1. Which of the following is not true about high-level programming language s? (a) Easy to read and write (b) Popular among prog
    12·1 answer
  • Question 8 A data analyst is working with a data frame named stores. It has separate columns for city (city) and state (state).
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!