CS 112 - Lab 5
Doubly Linked Lists


Section 1: Introduction

The goal of this lab is to:

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:

	mkdir ~/cs112/lab5
	cd ~/cs112/lab5 
	cp ~cs112/lab5/* .

Section 2: Topics for Lecture

Section 3: Description of Assignment


You are to implement a doubly linked list in which each node contains information about a student:

Last name
Id number
GPA


Four operations will be available for manipulating the list:

Insert a node alphabetically by name (last name only)
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 position pointer.

The current position pointer will point to the following:

We guarantee that all names will be unique.

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.

Example output:

        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:

  • list.h

    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:

  • create_list()
  • create_node()
  • insert()
  • delete()
  • replace()
  • print_info()
  • list_empty()
  • set_position()
  • lookup()
  • traverse()

    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 ~/cs112/lab5 directory:

  • main.c (containing main())
  • list.c (containing all list operation functions)
  • list.h (containing all typedefs, prototypes, etc)
  • makefile

    Then, to submit your program(s) for grading, issue the command

    ~cs112/submit lab5

    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

    ~cs112/query lab5

    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).

    This weeks questions.

    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.