CS 102 Laboratory Session Ten

Reversing a String with a Stack

This is the week 13 Lab session, worth 5 points total.

Download the Lab10.cpp source code file. You can open it in Visual C++ and compile it in a default workspace.

Examine the code and modify the main() function to push a few characters onto the stack and pop them off again. What kind of a data structure is the stack ADT implemented with? (one point)

a. A bag.
b. An array.
c. A linked list.
d. A specially-built data structure.
e. A queue.

Then modify the main() function again to take in a character string from the keyboard, reverse it, and output it back to the console. (three points)

Next add a feature such that if the reversed string is the same as the input string, the program outputs "It's a palindrome!" (one point)



This page established November 6, 1999; last updated January 6, 2K, by Rick Wagner.