This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: !"#"$$ $ CMSC 216 Introduction to Computer Systems Lecture 11 Linked Lists (cont) & Assembly Language Programming Jan Plane & Pete Keleher {jplane, [email protected] Administrivia • Project 3a & Project 3b • Read Chapter 11, Reek • Exam – mean = 69% CMSC 216  Wood, Sussman, Herman, Plane 2 !"#"$$ & Deleting from a linked list CMSC 216  Wood, Sussman, Herman, Plane 3 5 8 12 NULL head 6 3 Tracing deletion int delete(Node **head, int value) { Node *prev = NULL, *current = *head; while (current != NULL && current>data != value) { prev = current; current = current>next; } if (current == NULL) return 0; /* not found */ if (prev != NULL) prev>next = current>next; else *head = current>next; /* deleted first item */ free(current); return 1; } CMSC 216  Wood, Sussman, Herman, Plane 4 !"#"$$ ! Doubly linked lists • We can have references in both directions • Allows use of only one pointer when performing some operations typedef struct dl_node { struct dl_node *prev; struct dl_node *next; int val; } DL_node; CMSC 216  Wood, Sussman, Herman, Plane 5 Deletion from a doubly linked list int delete(DL_node **root, int target) { DL_node *current; for (current = *root; current != NULL; current = current>next) if (current>val == target) break; if (current == NULL) return 0; if (current == *root) *root = current>next; else current>prev>next = current>next; if (current>next != NULL) current>next>prev = current>prev; free(current); return 1; } CMSC 216  Wood, Sussman, Herman, Plane 6 !"#"$$ ! Doubly linked lists • We can have references in both directions • Allows use of only one pointer when performing some operations typedef struct dl_node { struct dl_node *prev; struct dl_node *next; int val; } DL_node; CMSC 216  Wood, Sussman, Herman, Plane 5 Deletion from a doubly linked list int delete(DL_node **root, int target) { DL_node *current; for (current = *root; current != NULL; current = current>next) if (current>val == target) break; if (current == NULL) return 0; if (current == *root) *root = current>next; else current>prev>next = current>next; if (current>next != NULL) current>next>prev = current>prev; free(current); return 1; } CMSC 216  Wood, Sussman, Herman, Plane 6 !"#"$$ ' A SSEMBLY L ANGUAGE Chapters 3 and 4.1, Bryant and O'Hallaron CMSC 216  Wood, Sussman, Herman, Plane 7 Assembly language • The CPU uses machine language to perform all its operations • Assembly is a much more readable translation of machine language, and it is what we work with if we need to see what the...
View
Full
Document
This note was uploaded on 11/16/2011 for the course CMSC 216 taught by Professor Plane during the Spring '11 term at Maryland.
 Spring '11
 Plane

Click to edit the document details