Step 2

Step 2


Let's take a look at the linked list code in linkedlist.c. The CreateNode(), SetData(), and IsEmpty() functions all look like the ones you saw in class, using variables of type NODEPTR to access the parts of the linked list. But the Insert(), Delete(), and PrintList() functions have parameters that use a HEADSTRUCTURE struct.

The linked list we'll be using in this lab will use a head structure, which will contain information about the class list, which will be the entire linked list. Check out the Linked List & Head Structures page for their diagrams.

Okay...so let's make this program use a head structure.

  1. Replace the declaration of NODEPTR head in lab12.c to be a variable of type HEADSTRUCTURE named headStructure. This headStructure variable has the field in its struct that points to the linked list, so it's all in there.

  2. Initialize the newly defined headStructure by uncommenting the code in lab12.c.

  3. Compile the code and run it.

Move on to Step 3...


linux3[22]% gcc -ansi -Wall -c lab12.c lab12.c: In function 'main': lab12.c:34: warning: unused variable 'id' lab12.c: In function 'ReadFile': lab12.c:105: warning: unused variable 'tempNode' lab12.c:104: warning: unused variable 'tempStudent' linux1[2]% gcc lab12.o linkedlist.o linux1[3]% a.out data.txt Welcome to the last lab of the semester! :)