Question: Exercise 7:Now we consider an implementation of the Stack class using a linked list. The class definition and a partial implementation of the class are
Exercise 7:Now we consider an implementation of the Stack class using a linked list. The class definition and a partial implementation of the class are contained in inlab12b.h and in inlab12b.cc respectively. Copy these files to your account. Notice that the function member, push0, is incomplete. Complete this function. Exercise 8:Add a member function numOnStack() to the class that returns the number of elements on the stack Exercise 9:The program main 12.cc used the stack class to print a string in reverse order. Notice that the code in that program is independent of the implementation of the Stack class. Turn in a listing of the files inlab 12b.h, inlab12b.cc and main 12.cc together with a compile and run to demonstrate that the code written in Exercises 5 and 6 is working Exercise 10: We are going to modify the program main12.cc to read a string and determine if the string is a palindrome. A palindrome is a string which is the same whether the characters are read from left to right or from right to left. For example "radar", "deed", and "able was I ere I saw elba" are all examples of palindromes There is a simple algorithm to determine whether a string is a palindrome push each letter of the string on a stack. Also place the charact into a character array, say str. Set j-0 and donefalse While the stack is not empty and not (done) pop a character, say ch if str[j] ch then increment j and continue else set done to true (the string isn't a palindrome) if done is true the string isn't a palindrome else it is. The first part of main 12.cc needs to be modified slightly. It already reads a string and pushes it on a stack. The string also needs to be saved in a character array Modify the program to correspond with the algorithm above. Turn in a listing compile and run of this modified program. Test your program with the strings listed above and with a string which is not a palindrome to demonstrate that it works
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
