Step 2

Step 2


Let's take a look at the linked list code. Open the files: linkedlist.c. and linkedlist.h and keep them open.

The CreateNode(), SetData(), Insert(), Delete(), IsEmpty() and PrintList() functions all look like the ones you saw in class, using variables of type NODEPTR to access the parts of the linked list.

In this lab, we'll be using multiple linked lists so we'll be using an array of NODEPTRs where each element of the array is the head of a list. Each list will contain information about the students in one TA's sections. Check out the Linked Lists & Using Multiple Linked Lists page for the diagrams pertaining to this exercise.


Okay...so let's make this program use the array of heads. Open the file: lab12.c

  1. Replace the declaration of NODEPTR head in lab12.c to be an array of NODEPTRs called sections of size NUM_SECTIONS.

  2. It is CRITICAL to begin with empty lists. To initialize the heads held in the array to NULL, thereby making three empty lists, uncomment the code in lab12.c.

  3. Since each of the lists corresponds to one of the TAs, use #defines with the TAs' names for the indexes of the sections array. DAVID's students will be in the first list, JULIA's students in the second list and AAFREEN's students in the third list. Add those #defines at the top of the lab12.c file.

  4. Compile the code and run it.

Move on to Step 3...


linux1[13]% gcc -ansi -Wall -c lab12.c lab12.c: In function 'main': lab12.c:40: warning: unused variable 'id' lab12.c: In function 'ReadFile': lab12.c:127: warning: unused variable 'taName' lab12.c:126: warning: unused variable 'tempNode' lab12.c:125: warning: unused variable 'tempStudent' linux1[14]% gcc lab12.o linkedlist.o linux1[15]% a.out data.txt Welcome to the last lab of the semester! :)