CSCI 1120 (Low-Level Computing), Spring 2009:
Homework 6
- Assigned:
- April 13, 2009.
- Due:
- April 20, 2009, at 5pm.
- Credit:
- 20 points.
Be sure you have read, or at least skimmed, the readings for 4/13,
``Lecture topics and assignments'' page.
Do the following programming problems. You will end up with at
least one code file per problem.
Submit your program source (and any other needed files)
by sending mail to
bmassing@cs.trinity.edu,
with each file as an attachment.
Please use a subject line that mentions the course number and
the assignment (e.g., ``csci 1120 homework 6'').
You can develop your programs on any system that provides the
needed functionality, but I will test them on one of the department's
Linux machines, so you should probably make sure they work
in that environment before turning them in.
- (20 points)
Write a C program that implements and tests one of the
linked-list-like data structures listed below.
For ease of coding, just make the program self-contained
(rather than having it get input from a human),
similar to the example implementation of unordered singly linked lists we
looked at in class.
(You can find it linked from
the course ``sample programs'' page
here
-- it's the program for 4/13.)
You can put the whole program
in one file, or separate it into multiple files as I did in the
example.
Possible data structures are the following:
- Sorted singly linked list (of ints or another data type).
Include functions to
- create an empty list
- free all memory associated with a list
- add an element
- remove a selected element
(everywhere it occurs, or only the first occurrence),
- search for a selected element
(you could have it return something
consistent with the C89 idea of a boolean -- zero is
``false'' and anything nonzero is ``true'')
- print all elements of the list to a specified output
stream (you could also include a parameter for the
print format, as in the example program, or just
hardcode something).
You can add additional functions for extra credit (amount of
credit depending on difficulty).
- Unsorted or sorted doubly linked list
(of ints or another data type).
A doubly linked list is one in which each element has pointers
to both the next element and the previous element.
Include functions as for the sorted singly linked list
described above, plus a function to print the elements in
reverse order.
You can add additional functions for extra credit (amount of
credit depending on difficulty).
- Binary search tree (of ints or another data type).
This is a tree data structure in which
every node
has the property that all nodes in its left
subtree store values smaller than the value in
and
all elements in its right subtree store values larger
than the value in
. (If you haven't encountered this
data structure before, I can explain in more detail.)
Include functions to
- create an empty tree
- free all memory associated with a tree
- add an element (for simplicity, you can disallow
duplicates, and simply do nothing if a request is
made to add something that's already present)
- search for a selected element
(you could have it return something
consistent with the C89 idea of a boolean -- zero is
``false'' and anything nonzero is ``true'')
- print all elements of the tree to a specified output
stream (you could also include a parameter for the
print format, as in the example program, or just
hardcode something).
(This list doesn't include a function to remove elements
because that's trickier.)
You can add additional functions for extra credit (amount of
credit depending on difficulty).
- Some other data type whose implementation involves
dynamically allocated storage and pointers (but ask me
before you do this).
You're welcome to use the example from class as a model or
starting point,
but you will probably learn more if you write most of the
implementation of your chosen data structure yourself.
Your functions can be recursive, as in the example, or not.
Berna Massingill
2009-04-13