CPTR-142 Homework #10 - Due Friday 5/02/14
In class we reviewed the creation of a linked list where
the nodes in that list are created using dynamic memory
allocation and new nodes are inserted at the head of the
list and removed from the head of the list. This is a
First-In-Last-Out arrangement where the magnitude of data
is randomly scattered over the list unless the data were
pre-sorted before the list is created and the list created
in order.
Using the HW9 problem of storing grades, if nodes are linked
together so that grades are in order, i.e. the highest
score is in the top node and the lowest score in the bottom
node (i.e. tail node), then our existing print function
will displayed scores in decending order.
As defined in class, program # 10 is to modify program #9
(which in turn is based on the example program on the class
web page) to insert new nodes at the correct place so that
data is kept in decending numerical order.
Thus two functions (methods) will be modified or created:
- Modify the newNode function to insert the new
node based on its value rather than always at the head
- Add a delete function. It should cause the now
unused memory to be returned to the operating
system. (Within the delete function you will
use the delete keyword in this
syntax: delete name_of_pointer)
Call these functions in the main to demonstrate correct
operation and print out the result.
If you wish to write other functions as well that is ok.
Have some fun!
Bring a printout of your main.cpp
file to class. Email the main.cpp files to
me but as you do that change the name to: name_program10.cpp
where name represents your last name. And between name and
program10 is an underscore. I appreciate not having spaces
in your file names.
Larry Aamodt PhD, PE
Professor of Engineering and Computer Science
Walla Walla University
Contact:
via email: AamoLa (at) wallawalla.edu
via phone: x2058