CS 112 - Lab 5
Doubly Linked Lists
Section 1: Introduction
The goal of this lab is to:
- implement a doubly linked list in which list entries are sorted
according to one field, and
- design a complete program by yourself.
If you have not already done so, create a directory for this lab and
copy the lab 5 files into it. If you start off in your home directory you
can do the following:
cp ~cs112/lab5/* .
Section 2: Topics for Lecture
- Review of doubly linked lists
- Problem specifications
- Hints on how to approach this problem
- Simple examples on how to use the gdb debugger
Section 3: Description of Assignment
You are to implement a doubly linked list in which each node contains
information about a student:
Four operations will
be available for manipulating the list:
| Insert a node alphabetically by name (last name
| Delete a name from the list |
| Lookup a name and print associated info |
| Replace the GPA field of a person's record |
Examples which could be processed include:
|Insertion: ||I Roberts 12345 3.2 |
|Deletion: ||D Roberts |
|Lookup: ||L Roberts |
|Replacement: ||R Roberts 3.5|
Your program will read the input from a file named input_file so,
brush up on your file I/O.
You will maintain a pointer that points to the last position visited in
the list and when a request is made, your program will compare the
name field of the node pointed to by the position pointer
with the the name field of the record you are processing. You must
decide which direction to traverse the list relative to the current
The current position pointer will point to the following:
We guarantee that all names will be unique.
- The node you are inserting
- The node you looked up
- The node in which you replaced the gpa
- The node before the one you deleted. If you deleted the first node,
current position will point to the head of the list.
In addition to the personal info in the node structure, there will
be one more field which holds the number of visits that node has received
during the course of the program. You will need to increment it each
time you visit a node. This way we can see if you are using the
current position pointer correctly.
Note: You should not count the initial insertion of a node into the
list as a visit for that particular node. You should only increment
the visits field of the struct Record for any node within
a single function, say SetPosition( ).
At the end of your program, the list must be traversed and the information
in each (including the number of visits field) printed to stdout.
NAME ID GPA VISITS
Brown 12345 3.1 2
Evans 54321 4.0 1
Finch 12342 2.1 1
Solo 32321 3.8 2
You must have a header line and a blank line followed by the lines of
information. Please use this format for your printf statement:
"%-10s %-5d %-3.1f %d"
Section 4: Code Development
You will be given the following files:
which contains some typedefs and structs to use for your linked lists.
Since you will not be given code as in past labs,
we suggest writing the following functions:
Remember to use stubs in your top-down algorithm design.
Section 5: Handing in your C code and answers
When you have completed this lab assignment, you should have the following program(s) in your
main.c (containing main())
list.c (containing all list operation functions)
list.h (containing all typedefs, prototypes, etc)
Then, to submit your program(s) for grading, issue the command
at your UNIX prompt. This utility program will copy your programs for grading and an electronic
mail message will be sent to you to acknowledge your submission. You may check the status of
your submission at any time by typing the command
at your UNIX prompt. You will automatically receive an electronic mail message confirming the
status of your lab submission.
You should also answer the questions below and submit them in hardcopy to the TAs at the
beginning of Lab 6 on March 14 (no late submissions accepted).
For credit on this lab, your software must be received by midnight
Friday, March 14 and your answers
to the lab questions must be received at the beginning of your lab section
(8:00am or 11:10am) on Friday, March 14.
Note: Always bring your ID with you to lab.