CMPS-2020 Programming II: Data Structures and Algorithms
Lab-8

Components:

Lab Details

Do your work in your Odin 2020/8/lab8.cpp

Start by copying the given program framework.

cp /home/fac/gordon/p/2020/code/lab8/flood.cpp .

1. This program works with a stack.
   Your job is to make it work with a queue.

2. Make the stack and queue class templates.
   The stack and queue should handle any data type.

3. Add this option...
   Allow the user to select the fill-character.
   Do not use cin.

4. Show a command-line Usage statement when no options are
   entered on the command-line.

5. You may change the shape of the maze as long as it demonstrates
   the proper functionality.


flood fill

Pseudocode for flood-fill function

function floodfill(starting_node, fill_char)
    save_char <- character at the coordinates of the starting_node
    enqueue the starting node
    while queue is not empty do
        dequeue a node
        color the node location with the fill_char
        visit all neighbors of the current node
           . visit node above, below, to left, to right
           . do not go out of array bounds
           . only visit if char equals save_char
           . do not visit a node multiple times
    end-do
end-function

Program output will look like this
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x x x xxxxxxxxxxxx x x xxxxxxxxxxxxxxxxxxxxxx x x xxxxxxxxxxxxxxxxxxxxxxxxx x x xxxx xxxx x x xxx xxxxxxxxxxx xxx x x xxx xxxxxxxxxxxxx xxx x x xxx xxxx xxxx xxx x x xxx xxx xxx xxx x x xxx xxx xxx xxx x x xxx xxxx xxxx xxx x x xxx xxxxxxxxxxxxxxxxxxxx x x xxx xxxxxxxxxxxxxxxxxx x x xxxx x x xxxxxxxxxxxxxxxxxxxxxxx x x xxxxxxxxxxxxxxxxxxx x x xxxxxxxxxx x x x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Program output will look like this
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x......................................x x..............xxxxxxxxxxxx............x x.........xxxxxxxxxxxxxxxxxxxxxx.......x x.......xxxxxxxxxxxxxxxxxxxxxxxxx......x x......xxxx...................xxxx.....x x......xxx.....xxxxxxxxxxx.....xxx.....x x......xxx....xxxxxxxxxxxxx....xxx.....x x......xxx....xxxx.....xxxx....xxx.....x x......xxx....xxx.......xxx....xxx.....x x......xxx....xxx.......xxx....xxx.....x x......xxx....xxxx.....xxxx....xxx.....x x......xxx....xxxxxxxxxxxxxxxxxxxx.....x x......xxx.....xxxxxxxxxxxxxxxxxx......x x......xxxx............................x x.......xxxxxxxxxxxxxxxxxxxxxxx........x x.........xxxxxxxxxxxxxxxxxxx..........x x.............xxxxxxxxxx...............x x......................................x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Correct program output is this...
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx x......................................x x..............xxxxxxxxxxxx............x x.........xxxxxxxxxxxxxxxxxxxxxx.......x x.......xxxxxxxxxxxxxxxxxxxxxxxxx......x x......xxxx...................xxxx.....x x......xxx.....xxxxxxxxxxx.....xxx.....x x......xxx....xxxxxxxxxxxxx....xxx.....x x......xxx....xxxx xxxx....xxx.....x x......xxx....xxx xxx....xxx.....x x......xxx....xxx xxx....xxx.....x x......xxx....xxxx xxxx....xxx.....x x......xxx....xxxxxxxxxxxxxxxxxxxx.....x x......xxx.....xxxxxxxxxxxxxxxxxx......x x......xxxx............................x x.......xxxxxxxxxxxxxxxxxxxxxxx........x x.........xxxxxxxxxxxxxxxxxxx..........x x.............xxxxxxxxxx...............x x......................................x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Notice the center is not filled-in. This is the correct behavior of a flood-fill operation. The center is an isolated area with no way to enter. To fill that area, you must start the flood-fill within the area.

Homework
What you don't finish in the lab becomes homework.

How to approach the homework program:

1. Write a stack class for data type char.
   The stack holds characters.

2. Define a character string that holds a word like "hello".

3. The string is an array, so read each array element and push
   it onto your stack.

4. Create another character string array.
   Pop a letter from the stack and save it in the first array element.
   Pop another letter and save it in the 2nd array element.
   Pop as meny letters as there are in the word.
   Make sure your character string has a null terminator.

5. Display the new word.

6. When you get that working, instead of 1 word, use the dictionary words.
   Only print the word if the new word is the same as the old word.

7. When all this works, make your stack a template.

in summary...
   a. Get it working with one word.
   b. Send in dictionary words.
   c. Make it a template.

Part a will earn points.
Part b will earn points.
Part c will earn points.

You have to get something working.

Copying a program that is already written on the Internet will earn
you no points. Stop doing that please. Learn the material and write
your own programs.

Homework
Name your program: 2020/8/mystack.cpp

Write a program that contains a stack data structure.

Build your stack as a class template.
See Gaddis chapter 16, page 996 (edition-8).

Step-1

   Your program will read each word of the Odin file...
   /usr/share/dict/cracklib-small
   and store it in a string.
   You may use string or c-string.

NOTICE:
DO NOT make a local copy of the dictionary file!
Open it from where it is now.
The path and filename is shown above.


Step-2

   Read a word.
   If word length is less than 3, skip the word.

Step-3

   Push each individual character of the word onto your stack.

Step-4

   Define a temporary string that can hold a word as long as your current word.

   Your program will now pop the characters from the stack and save them
   one at a time in your temporary character string.

   This will give you a new word with the letters backwards.

Step-5

   Compare your word with the temporary (backwards) word.
   If they are equal, then display the word.


Your program output should be clear and concise.

Clear and concise means...
  1. The program user will know why the program was written.
  2. The program user will know what data they are seeing.
  3. The output will be easy-to-read.
  4. The program output will fit on one terminal screen, without scrolling.

What to turn in...
Your instructor will find your work out on Odin.