Question: Overview For this assignment you will be creating a multi - file project in which you implement your own templated linked list and use it
Overview
For this assignment you will be creating a multifile project in which you implement your own
templated linked list and use it to create a simple list of composers. When doing this
assignment, take small, incremental steps; trying to complete the lab in one go will make the lab
more difficult. This means that any time you finish part of the lab, such as a linked list method,
you should immediately test and debug it if necessary.
Part : Creating your Linked List
Create a header file, Node.h that has a templated class called Node This class should be able
to hold both a data value and a pointer to another node.
Once your node class is complete, create a new header file, LinkedList.h that has a templated
class called LinkedList The class should have two member variables: a pointer to the first
element of the linked list and a pointer to the last element of the linked list.
Additionally, the class will need to have the following methods do not define them inline Some
methods may only have a few lines while others are more complicated and will require a bit
more thought. Make sure you test all cases for each method and appropriately update the
pointers to the first and last nodes if needed.
LinkedList;
Constructor for linked list. You decide what needs to be done here
~LinkedList;
Destructor for linked list. You decide what needs to be done here
void printList const;
Displays all elements in linked list. This is one of the most important methods
because it gives you a way to test your code! For example, once you write the append
method, you should test it using printList
void appendconst T data;
Adds a node to the end of the list. For example:
list
list.append
list
void prependconst T data;
Adds a node to the front of the list. For example:
list
list.append
list
bool removeFront;
Removes the front node. For example:
list
list.removeFront
list
void insertconst T data;
Accepts a value and will insert the value into the linked list in the correct order.
list
list.insert
list
list.insert
list
list.insert
list
bool removeconst T data;
Accepts a value and will remove the node with that value from the list. Return true if the
node was found and removed and return false otherwise.
list
list.removereturns true
list
list.removereturns false
list
bool findconst T data;
Accepts a value and will search for that value in the linked list. Return true if the value is
in the list and false otherwise
bool isEmpty const;
Returns true if list is empty and false otherwise
T getFirst const;
Returns the value stored in the first node of the list not a pointer to the node
T getLast const;
Returns the value stored in the last node of the list. For example:
list
list.getFirstreturns
list.getLastreturn
Note: Remember that your linked list needs to have both a pointer to the first node and a pointer
to the last node The book has code for a templated linked list, but it only has a head pointer.
You will not be able to directly copy out of the book Keep this in mind when writing your
methods. For example, what is different about the remove method if we remove a node from
the front vs a node at the end vs a node in the middle? What about if the list is empty?
Part : Using your linked list
You will now test your linked list by creating a simple list of composers using the input below.
composers.txt
Ludwig van Beethoven,
Wolfgang Amadeus Mozart,
Johann Sebastian Bach,
Frederic Chopin,
George Frideric Handel,
Franz Liszt,
Johannes Brahms,
Igor Stravinsky,
Pyotr Ilyich Tchaikovsky,
Claude Debussy,
Joseph Haydn,
Gustav Mahler,
Sergei Prokofiev,
Richard Wagner,
Giacomo Puccini,
Felix Mendelssohn,
Aaron Copland,
Franz Schubert,
Giuseppe Verdi,
Maurice Ravel,
Dmitri Shostakovich,
Sergei Rachmaninoff,
Arnold Schoenberg,
George Gershwin,
Robert Schumann,
Leonard Bernstein,
Bela Bartok,
Antonin Dvorak,
Antonio Vivaldi,
Edvard Grieg,
Camille SaintSaens,
Henry Purcell,
Claudio Monteverdi,
Hector Berlioz,
Each entry in the file consists of two data fields: the composers name and the date of death.
Instead of creating two separate linked lists, we will take advantage of the fact that our linked list
is a template and can hold any generic type. Our generic type will be a new class.
First create a new header file, Composer.h; the class should have two member variables to hold
the composers name and the date of their death. It is
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
