[Type C]Q2. A line of text is read from the input terminal into the stack. Write a program to output the string in reverse order, each character appearing twice.

What is a Stack?

A stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). Consider an example of plates stacked over one another in the canteen. The plate which is at the top is the first one to be removed, i.e. the plate which has been placed at the bottommost position remains in the stack for the longest period. 

Operations of Stack:

Mainly the following two basic operations are performed in the stack:

  • Push: Adds an item at the top of the stack. If the stack is full, then it is said to be an Overflow condition.
  • Pop: Removes an item from the top of the stack. If the stack is empty, then it is said to be an Underflow condition.

Problem: A line of text is read from the input terminal into the stack. Write a program to output the string in reverse order, each character appearing twice.

Program code:

Output:

Enter a String: ComputerTutor rroottuuTTrreettuuppmmooCC

In the above code snippet basic functions of stack are demonstrated.

To view all the lessons in chapter 10: http://computertutor.in/class-12-computer-science/chapter-10/

To view entire class 12 computer science study material: http://computertutor.in/resources/

You cannot copy content of this page