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
You need to store product quantities, and you want to minimize the amount of storage space that is used. Which data type should
Inga [223]

Answer:

win-RAR or other kind of compactor

Explanation:

Also you may use Cloud or Dropbox

7 0
4 years ago
How does object-oriented programming work in Python?
Serggg [28]
So basically you have a class, and within that class you have methods and instance variables; very much like how object oriented programming works in other languages. However, the main difference is that the class constructor in Python is defined right within the class object and is denoted by the method name, "__init__" and requires a parameter of "self". 
Ex:
class Py:
    def __init__(self):
          <em>constructor code...
</em>The __init__ method is what is called first when an object of the class is instantiated. The way you instantiate an object is by the following:
<em />object_name = Py()

If you wanted to make your class more useful, you could add more parameters to your __init__ constructor, so when an object is created you can pass arguments to that object:
class Py:
    def __init__(self, name, age):
         self.name = name
         self.age = age
         print "Your name is %s and you are %d years old" % (name, age)
def main():
     Bob = Py("Bob", 23)
if __name__ == "__main__":
     main()

This code would give you: Your name is Bob and you are 23 years old
3 0
3 years ago
Both the cancel button and the enter button appear on the formula bar when you begin typing in a cell.
Serjik [45]
The answer is true both appear on the formula bar
7 0
3 years ago
A _______ object is used for storing data.
max2010maxim [7]

Hard dirve.  Hard drive is a high-capacity, self-contained storage device containing a read-write mechanism plus one or more hard disks, inside a sealed unit.

6 0
4 years ago
To write 10 lines of code on paper:
marusya05 [52]

print("enter numbers between 1 and 10")

num1=float(input("enter the first digit to add together"))

num2=float(input("enter the second digit to add together"))

if num1 and num2 >=10:

answer=num1+num2

print(answer)

else:

print("answer not accepted please try again later")

exit()

4 0
3 years ago
Other questions:
  • A. When executing System.out.println(a1), the toString() method in the Object class is invoked.
    14·1 answer
  • Software that interprets commands from the keyboard and mouse is also known as the?
    15·1 answer
  • Which element in the PowerPoint application is not available in the Microsoft Word application?
    12·2 answers
  • Write a program that reads a list of integers, and outputs whether the list contains all even numbers, odd numbers, or neither.
    10·1 answer
  • The process of securely erasing a hard drive
    12·1 answer
  • Write an abstract data type for a queue in Java whose elements are generic elements of type T that have an associated integer pr
    15·2 answers
  • Design a function int maxDigit (int num) to find and return the greatest digit from the arguments value num.
    13·1 answer
  • ILL GIVE BRAINLIEST. Read about one many types of computer languages that are available for computer coders. Use the website lis
    15·1 answer
  • Is this statement true or false? While in slide show mode, if you are not careful you can close the application by clicking the
    10·1 answer
  • You need to design an online login form in which users have to type their name and password to log into an application. The pass
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!