Theres a missing file thats needed by test 10. Follow these instructions to copy it into your lab6 directory. Follow these instructions only if you have started working on lab6. If you havent downloaded the lab6-src.tar file yet, then, you may ignore this post as the new tar file already includes this file.
cd ~/cs240/lab6-srccp /homes/cs240/lab6-linkedlists/table1.ll .
Examine the output line by line and see if the values of p in the output after incrementing are what you expect. The instructors will make sure that you have examined the code and the output. Be prepared to answer the instructors questions about the code.
Step 3. Using ddd to Debug a Simple List.
You are given a simple_list.c file that implements a simple linked list.
// Simple list of integers struct ListNode { int value; struct ListNode *next; };
typedefstruct ListNode ListNode;
struct ListNode *head = NULL;
voidaddFront(int val){ // Create new node ListNode * n = (ListNode *) malloc(sizeof(ListNode)); n->value = val;
// Add at the beginning of the list n->next = head; head = n; }
voidprintList(){ // Traverse list ad print elements printf("---List---\n"); ListNode * n = head; while (n!=NULL) { printf("%d\n", n->value); n = n->next; } }
The struct ListNode stores an integer value and has a pointer to the next node in the list. The variable head points to the first node in the list. addFront(int val) adds a new node to the front of the Linked List. The function printList traverses the list to print all the elements in the linked list.
Compile simple_list using make and run ddd.
makeddd simple_list
Follow the video Debugging Linked Lists in DDD. This video is hosted in the blackboard website so you will need to type your Purdue user and password. If you have problems with this link login to blackboard directly and go to the class blackboards webpage. The video is also available there.
Set a breakpoint by selecting double click at the beginning of the list.
Step through each line in the code and double click in head. This will show the value of the head. Now point in the next address to show the next node in the list.
It is important that you do this tutorial and watch the video to be able to debug the linked lists operations you will implement later.
To show the line number in DDD press Edit->Preferences->Source and mark the checkbox Display Source Line Numbers.
Step 4. Implementing a Linked List of ints
The files LinkedList.h and LinkedList.c implement a linked list of ints. Complete the implementation of the functions indicated in LinkedList.c. Run testall to verify that your implementation is correct. LinkedList.h
e = list->head; while (e != NULL) { printf("%d", e->value); e = e->next; if (e!=NULL) { printf(", "); } } printf("}\n"); }
// // Appends a new node with this value at the beginning of the list // voidllist_add(LinkedList * list, int value){ // Create new node ListNode * n = (ListNode *) malloc(sizeof(ListNode)); n->value = value;
// Add at the beginning of the list n->next = list->head; list->head = n; }
// // Returns true if the value exists in the list. // intllist_exists(LinkedList * list, int value){ return0; }
// // It removes the entry with that value in the list. // intllist_remove(LinkedList * list, int value){ return1; }