CSE 240 – Assignment 6
Points: 50 pts
Topics:
• C/C++ Syntax
• Pointers
• Functions
• Dynamic Allocation of Memory
• Data Structures: Linked Lists
• Object Orientation
Overall Specifications:
You are to create a Linked List or Binary Search Tree data structure from
scratch. This structure should be Templated so that any data could be stored
within it.
For a maximum of B on specifications – you can make your structure
non-templated – meaning it stores only the data required for the
problems.
The primary goal of this assignment is to make a Linked List that you can use and
e-use. The Linked List itself is the majority of the specifications grade.
Specifications Scoring Breakdown:
Templated Linked List/BST + Problem – 100% of specifications
Templated Linked List/BST only – 80% of specifications
Untemplated Linked List/BST + Problem – 80% of specifications
Untemplated Linked List/BST only – 70% of specifications
** BIG GIANT NOTE – TEMPLATES AND FILES **
When you use a templated type in C++ ALL templated code must be done in the .h
file. This means that ALL of your methods will be defined in the .h file as well
as your class.
You should still forward declare Classes above then Methods below.
Your .h file should have your LinkedList/BST class and your Node class and the
method definitions for both. Remember to use your :: operator co
ectly.
Feel free to use friendship if needed.
Option 1
Zombie Conga Party! - Linked Lists
You will create a Linked List Class and a Node Class
The Linked List should contain the following methods in its public interface:
NOTE: T stands for the template data type, so T data means the variable of type T
(whatever T is)
• Constructor
• Destructor
• AddToFront(T data) – create a node containing T data and add it to the front of the
list
• AddToEnd(T data) – create a node containing T data and add it to the end of the
list
• AddAtIndex(T data, int index) – create a node containing T data and add it to the
list at index. The new node containing the data will be the #index node in the
list. Return boolean for success or failure (optional: you could also return an
integer with failure codes since this method can fail multiple ways)
• RemoveFromFront() – Delete first item and return its contents
• RemoveFromEnd() – Delete last item and return its contents
• RemoveTheFirst(T data) – find first instance of T data and remove it
• RemoveAllOf(T data) – find each instance of T data and remove it
• ElementExists(T data) – Returns a T/F if element exists in list
• Find(T data) – Look for data in the list, return a pointer to its node
• IndexOf(T data) – returns an index of the item in the list (zero-based)
• RetrieveFront – returns the data contained in the first node, does not delete it
• RetrieveEnd – returns the data contained in the last node, does not delete it
• Retrieve(int index) – returns the data contained in node # index, does not delete
it, returns null if index is out of bounds or data does not exist
• PrintList – Loop through each node and print the contents of the Node
• Empty – Empty out the list, delete everything
• Length – How many elements are in the list
More methods private or public should be created as needed to facilitate the
functionality of the Interface methods. If you feel your list needs more
functionality, feel free to create it.
As per usual, I have not made a perfect representation of the parameters you
might need, etc. I have made suggestions where appropriate, but you might need
more depending on how you code things.
Node Class
• Constructor
• Destructor
• Getters & Setters
The node class should be fairly rudimentary. Ideally, it should be templated so
you can store anything in it.
Description:
You are going to create a silly Zombie Conga Line using your Linked List.
Each node is going to store a Zombie in it. Zombies can be Red, Yellow, Green,
Blue, Magenta and Cyan.
Every turn you will randomly generate a Zombie object and an action. You will
then perform that action using the Zombie object as the parameter for that
action.
NOTE – these actions are external to the Linked List. They are accomplished by
calling Linked List methods.
Actions:
• Engine!
o This zombie becomes the first Zombie in the conga line
• Caboose!
o This zombie becomes the last zombie in the conga line
• Jump in the Line!
o This zombie joins the conga line at position X where X <= length of
the linked list
• Everyone Out!
o Remove all matching zombies from the linked list
• You’re done!
o Remove the first matching zombie from the linked list
• Brains!
o Generate two more matching Zombies and add one to the front, one to
the end and one to the middle.
• Rainbow Brains!
o Add this zombie to the front, then add one of each zombie color to the
end of the conga line.
Every 5 rounds remove the Head zombie and Tail zombie.
Setting up the List:
Set up the initial Conga Line by running these actions:
1. Run a Rainbow Brains! Action
2. Run a random number (between 2 and 5) of Brains actions
User Interface:
• Ask the user how many rounds they want to run.
• Then generate that many random actions and fulfill them.
• If the conga line ever empties completely due to an action tell the user
that the Party is Over.
• Once the number of rounds has finished. Ask the user if they want to
continue the party or end.
• If they choose to continue ask them for a new number of rounds to run.
Output:
Each round you’ll output the entire Linked List. You can represent each zombie
as a single character co
esponding to their color (R, Y, G, B, M, C).
Have fun, make silly messages and color the output if you like!
You’ll show the zombie generated and the action generated.
Then you’ll show the outcome of the action.
Spelling it out for you:
You should create the following classes:
1. LinkedList
2. Node
3. Zombie
Your Nodes should store Zombies.
Your LinkedList is made of Nodes.
Hints:
Build robust constructors and use them! Your Node and your Zombie will benefit
highly from good constructors.
Do yourself a favor and overload the == operator in your Zombie. It will make
life easier!
Overload the cout for your Zombie. It’ll make your printList method easier.
You might consider making the Conga its own class so you can make each of the
actions a method in the conga class.
Extra Credit:
+2 – Color your Zombies in the output.
Sample output:
Round: 0
The Zombie Party keeps on groaning!
Size: 16 :: [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R]
B zombie jumps in the front of the line! (ENGINE)
The conga line is now:
Size: 17 :: [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R]
*******************
Round: 1
The Zombie Party keeps on groaning!
Size: 17 :: [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R]
M zombie jumps in the front of the line! (ENGINE)
The conga line is now:
Size: 18 :: [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R]
*******************
Round: 2
The Zombie Party keeps on groaning!
Size: 18 :: [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R]
C zombie pulls up the rear! (CABOOSE)
The conga line is now:
Size: 19 :: [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R] [C]
*******************
Round: 3
The Zombie Party keeps on groaning!
Size: 19 :: [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R] [C]
Y zombie
ought a whole party itself! (RAINBOW BRAINS!)
The conga line is now:
Size: 26 :: [Y] [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R] [C] [R] [G] [B] [Y] [M]
[C]
*******************
Round: 4
The Zombie Party keeps on groaning!
Size: 26 :: [Y] [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [M] [C] [G] [M] [R] [C] [R] [G] [B] [Y] [M]
[C]
Y zombie
ings its friends to the party (BRAINS!)
The conga line is now:
Size: 29 :: [Y] [Y] [M] [B] [R] [M] [G] [R] [R] [G] [G] [R] [M] [B] [Y] [Y] [M] [C] [G] [M] [R] [C] [R] [G] [B]
[Y] [M] [C] [Y]
*******************
NOTE:
You don’t have to use my messages, I just made them on a whim. Do however follow
my lead and put a label showing what action the message represents.
Don’t forget to output the list before and after the action.
Option 2:
Word Frequency Analysis – Binary Search Tree
You will create a Binary Search Tree Class and a Node Class/Struct
The Binary Search Tree should contain the following methods in its public
interface:
• Constructor
• Destructor
• Insert(T data) – create a node containing T data and add it to the tree (REMEMBER:
NO DUPLICATES)
• Remove (T data) – find instance of T data and remove it
• ElementExists(T data) – Returns a T/F if element exists in tree
• Find(T data) – Look for data in the list, return a pointer to its node
• ToA
ay – Create an a
ay from the contents of the tree and return it
• Empty – Empty out the list, delete