Laboratory Exercise on Linked Lists
This laboratory helps you gain more experience with the use of lists and pointers.
Steps for this Lab
This lab involves working with lists of data, using an existing driver program which actually constructs the lists. In particular, the file actionlist.c contains a menu-driven program to maintain a list of robot actions and their corresponding names.
As written, the program contains functions to insert an action on the list (before a designated node), to delete a specified action from the list, to print the actions in the list, and to execute all the actions in order.
Copy actionlist.c to your account, compile it, and run it several times to discover just what the program does.
Make sure you turn the robot on before calling the E (execute) option.
As you may have discovered, in addition to the above features, program actionlist.c contains several stubs for additional functions, but details of these functions are not given. Your task in this lab is to implement these new functions on the menu. (Don't forget to add the prototype before main if you can write the functions at the bottom.)
Write the details for countList (struct Node * first) which counts the number of items in the list.
To perform this task, you will want to move along the list item-by-item, counting the items as you go.
Write the details for function printReverse (struct Node *first), that prints the names in the actionData structures in the nodes from the last node to the front.
Hint: The C code can follow the same approach you used often in Scheme (think recursively).
Write a function reverseActions that executes all the actions in the list from the last node to the front. This should be very similar to printReverse except it will call the void functions stored in the actionData structs rather than print out the names.
* Note: You will also need to add a menu option for this function in main.
Extra Extra Credit!
You may have noticed the F, L, and R options are still not implemented.
Complete these function stubs so you have a fully working robot movement suite.
If you are having trouble, read the addAction and deleteAction functions to see how modification of the list nodes is handled.
It is important to realize a list node is identified by its UID rather than the data it contains. When asking and searching for nodes, use the UID to match the node and not the data field.
Why might a UID be used in this case rather than just the data that the list contains?
Reminder: Complete Evaluation Form
When you have finished this lab, be sure to fill out its evaluation form in the "Lab Evaluation" section for CSC 161 on Pioneer Web.