Step 5


Okay, the linked list deleted items as predicted. But we really aren't using the head node to its full potential!

It's definition in linkedlist.h looks like:

typedef struct headStructure { int numNodes; /* number of nodes in the list */ int classSum; /* sum of grades in the entire list */ NODEPTR head; /* will point to the start of the list */ } HEADSTRUCTURE;

To keep track of the number of nodes in the list, code will need to increment or decrement the numNodes field as nodes are added or deleted. The classSum is the grand total of all the scores for the class, so as student nodes are added to or deleted from the list, the classSum will have to be adjusted as well.

  1. Uncomment the lines of code in Delete() in linkedlist.c.

  2. Add lines of code in Insert() in linkedlist.c that change the headStructure as nodes are added.

  3. Recompile the code. Note that your output won't change from the last step.

Go on to Step 6...


linux1[1]% gcc -Wall -ansi -c linkedlist.c linux1[2]% gcc lab12.o linkedlist.o linux1[3]% a.out data.txt Welcome to the last lab of the semester! :) First Name Last Name ID Grade -------------------- -------------------- ------------ ------- Ann Lewis 123 98% Joseph Eisenhower 212 82% Mary Jones 634 85% Mark Johnson 345 78% Justin Lewis 122 99% Jenny Garcia 121 87% Gary Watson 532 92% Jamie Casselman 621 100% Samantha Warrez 124 86% Bob Ramsey 141 64% Claire Dishon 161 76% Please enter the id# to delete from the list: 123 Student was successfully deleted from class list. First Name Last Name ID Grade -------------------- -------------------- ------------ ------- Joseph Eisenhower 212 82% Mary Jones 634 85% Mark Johnson 345 78% Justin Lewis 122 99% Jenny Garcia 121 87% Gary Watson 532 92% Jamie Casselman 621 100% Samantha Warrez 124 86% Bob Ramsey 141 64% Claire Dishon 161 76% linux1[4]%