Step 4


That's a pretty nice linked list you got there! But let's test the dynamic nature of a linked list. In arrays, if you want to delete an element, you either have to resize the array and copy its contents back and forth, or swap some elements and ignore others. No fun either way. So let's delete an element the linked list way--by calling Delete(). Don't worry, it's already written for you.

  1. In lab12.c, uncomment the lines of code that prompt and get an id number from the user to delete from the class list.

  2. In lab12.c, uncomment the lines of code that attempt to delete a student with the entered id.

  3. Call PrintList() to verify that the list shrunk correctly.

Moving on to Step 5...


linux1[1]% gcc -Wall -ansi -c lab12.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: 0 Student was NOT in the class list. 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% linux1[4]% 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: 141 Student was successfully deleted from class list. 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% Claire Dishon 161 76% linux1[5]%