Corning Community College
Data Structures
Linked List Knowledge Assessment: From Code to Diagrams
Open resource, closed person- do not communicate with anyone other than the instructor regarding material contained therein.
This is not take home- this is to be done during sanctioned times in the LAIR. If you do not finish, you may be able to resume work on following days (but note there may be additional content on following days).
There is the possibility of being asked to write code, debug, or draw diagrams– all related to content and concepts we have covered.
Following will be common code utilized by the following questions:
struct node { int value; struct node *next; struct node *prev; };
struct list { struct node *start; struct node *end; };
struct node *func1(int val) { int i = 0, old = 0; struct node *tmp, *tmp2; tmp = tmp2 = create(); tmp -> value = 1; for(i = 0; i < val; i++) { tmp2 -> next = create(); tmp2 -> next -> value = tmp2 -> value + old; old = tmp2 -> value; tmp2 = tmp2 -> next; } tmp2 -> next = tmp; return(tmp2 -> next); }
struct node *func2(int val) { int i = 0; struct node *tmp, *tmp2; tmp2 = create(); tmp = tmp2; tmp -> value = val; while (i < val) { tmp -> next = create(); tmp -> next -> value = i; tmp = tmp -> next; i++; } return(tmp2); }
struct node *func3() { struct node *tmp, *tmp2; tmp = tmp2 = create(); tmp2 -> next = create(); tmp -> next -> prev = tmp2; return(tmp); }
struct node *func4(struct node *tmp) { while (tmp -> next != NULL) { tmp = tmp -> next; } return(tmp); }
Draw the diagram of the resulting linked data structure from a program that consists of the following:
struct node *stuff; stuff = func2(8);
Assume the state immediately following the function call, return, and resulting assignment to stuff.
Draw the diagram of the resulting linked data structure from a program that consists of the following:
int i = 5; struct node *tmp, *tmp2, *a, *b, *c, *d; b = c = tmp = NULL; d = tmp2 = a = NULL; for(i = 0; i < 4; i++) { if(tmp == NULL) { tmp2 = tmp = create(); tmp -> value = i; tmp -> next = create(); tmp -> next -> value = i + 4; a = tmp2 -> next; tmp = tmp -> next; } else { tmp -> next = create(); tmp -> value = i; tmp -> next -> value = i + 4; if(i == 1) b = tmp -> next; else if(i == 2) c = tmp -> next; else d = tmp -> next; tmp = tmp -> next; } } tmp -> next = tmp2; tmp -> value = i; tmp = tmp -> next -> next -> next;
Draw the diagram of the resulting linked data structure from a program that consists of the following:
Analyzing the above code and your resulting linked data structures:
Your produced output from this activity will be hand-drawn diagrams of various linked data structures (as well as responses to indicated questions).
As such, before leaving, please hand in any such papers– even if not done, for there may be additional opportunities to work on it in future days.