Fun with Stacks

CS 3358

Due: Friday 10/24/08 at 10:00pm
100 points


Stack implementation notes:

1) You will be using List_3358 to implement Stack_3358. That means you will need to create a templatized version of List_3358 and of Stack_3358. You can use whatever actual implementation for the list that you want. Note that the implementations will move to the .h files.

2) You should add a function to List_3358 called insertAtHead() . That will make the Stack_3358 implementation much easier.

3) You may also add a constructor that passes in the size of the desired list. (and remove the constant from the List_3358.h file)

Equation Checker

Given an equation such as: ([1+3]-42/(4*4)) your task is to determine if the parenthesis, square braces, and angle braces  match. If they do, the ouput of the program will be "equation ok". If the equation has a problem, your output will reflect the error. For example: ((a+b+)  would result in "missing )" .

You can ignore the actual equation and just focus on the delimiters.
Note: You may assume the equation is at most 80 characters long.


Input to program - Put the test expressions in a file (for example, "exp.dat") one expression per line and then get the file name from the command line. 

if  the file exp.dat contained:

(<a+b>-6
[(hey)-9]

linux prompt > ./check exp.dat

(<a+b>-6   ===  missing )

[(hey)-9] === valid expression


Notes:

Turn in:  No hard copy source file turnin.

Submit: Using this link, the source file (.cpp)  


Flood Fill

Given an input file of the following format (a fake picture):

yyywwbbbbbbbggggg
yyybbbbbbbgggbbbb
ybybybybybwwwwwyy
ybbbbggwwwwwwbbbg
ggggggwwbbbbbbbbb
yyyyyyyyybbbyyyyy
ggggyyyygggggyyyy


that uses characters to represent colors in a picture, you will need to write a function that will "flood fill" an area with another "color." For example. If I were to flood fill the pixel at row 0 col 6 (a"b") with a "P", I would get this:

yyywwPPPPPPPggggg
yyyPPPPPPPgggbbbb
yPyPyPyPyPwwwwwyy
yPPPPggwwwwwwbbbg
ggggggwwbbbbbbbbb
yyyyyyyyybbbyyyyy
ggggyyyygggggyyyy

Every pixel that has the same color and is connected to the area of the flood fill is changed to the new color.

Write a program that reads in a file (provided at the linux prompt) that is at most 25 rows and 25 columns and repeatedly prompts the user for a row and column number, and a "color".  The program will fill that area with the new color, show the new picture and prompt the user again.  The program will end when the user enters -1 for the row or column.

Example Run:

linux prompt> ./flood_fill fake_picture.txt

yyywwbbbbbbbggggg
yyybbbbbbbgggbbbb
ybybybybybwwwwwyy
ybbbbggwwwwwwbbbg
ggggggwwbbbbbbbbb
yyyyyyyyybbbyyyyy
ggggyyyygggggyyyy

Enter a row: 0
Enter a column: 6
Enter a color: P

yyywwPPPPPPPggggg
yyyPPPPPPPgggbbbb
yPyPyPyPyPwwwwwyy
yPPPPggwwwwwwbbbg
ggggggwwbbbbbbbbb
yyyyyyyyybbbyyyyy
ggggyyyygggggyyyy


Enter a row: 1
Enter a column: 1
Enter a color: G

GGGwwPPPPPPPggggg
GGGPPPPPPPgggbbbb
GPGPyPyPyPwwwwwyy
GPPPPggwwwwwwbbbg
ggggggwwbbbbbbbbb
yyyyyyyyybbbyyyyy
ggggyyyygggggyyyy


Enter a row: -1
Enter a column: 1
Enter a color: G



Notes:

Turn in:  No hard copy source file turnin.

Submit: Using this link, the source file (.cpp)  


Last Updated: 10/13/08