GATE Computer ScienceEasyGATE CS (PYQ pattern)

A routine reverses the entire string in place and then reverses each maximal run of non-space characters in place. It is applied twice in a row to "stack and queue". What is the string after the second application, and what is it after just the first?

  1. A. "queue and stack" and "stack and queue"
  2. B. "stack and queue" and "queue and stack"
  3. C. "eucuq dna kcats" and "queue and stack"
  4. D. "stack and queue" and "eucuq dna kcats"

Correct answer: B. "stack and queue" and "queue and stack"

One application reverses the order of the words (queue and stack); the second restores the original order. After one: "queue and stack"; after two: "stack and queue".

More Programming and Data Structures (GATE) questions

Exams that ask this topic