C++ Homework for Week 2.  



Write a program using the stack algorithm to solve the "pillar" problem.

Recall the pillar problem can be described as follows.

Input: A sequence of height values h[0 .. n-1], such that h[0] = 1 and 0 < h[i] < 1 for all i = 1, ..., n-1.
Output: For every pillar i, with 0 < i < n 1 report s[i], the label of the pillar to the left of pillar i that is illuminated by a point laser light
emitting from the top of pillar i.

Your program should allow you to easily change the value of n.
Your stack implementation is your choice. You may use an array (circular), a linked list, write your own generic stack class, or even use the STL stack class. Your choice of implementation method can be based on the method you think you need the most practice with. Or perhaps your current workload is heavy and you want to take an easy way out. If you have time you may actually try more that one method. Nevertheless, to get your point all you need to do is demonstrate a running program.
However, if you are up for a challenge, then the student(s) who has implemented a stack in the largest variety of ways will be singled out for special distinction!

 

Posted: Wed - January 10, 2007 at 12:51 PM          


©