Announcements Homework #7 due Monday at 3:00pm Submission instructions will be posted soon Homework #8 now available Be sure to fill out course evaluations! Upcoming office hours: Tomorrow: Sheng 12-1:30pm Monday: Chris 11am-12pm, 1:30-3pm 1 1 1 1 1 1 1
Homework #7: Makefile A Makefile is a configuration file that explains how to compile your code You specify “targets” that have dependencies and compilation commands Used for compiling your code, not running it Please include a Makefile for Homework #7 Just modify the one that we provide you 2 2 2 2 2 2 2
Upcoming Schedule Last time: structs and linked lists (chapter 19) Today: review of last time (malloc); more linked lists; queues Tuesday: more data structures Thursday: preview of CIT 595; final review 3 3 3 3 3 3 3
Key questions from last time Why can't a function that adds a new node to a linked list put it on the stack? What's this “malloc” thing all about? 4 4 4 4 4 4 4
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); ? k FP, SP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); 5 k FP, SP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); 6 d SP x456A 5 k FP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); SP ? RV x4569 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x1234 SP x4568 RA ? RV x4569 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); SP x4567 x456B FP x1234 x4568 RA ? RV x4569 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); SP x4566 ? x4567 x456B FP x1234 x4568 RA ? RV x4569 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 ? new.data x4566 ? new.next x4567 x456B FP x1234 x4568 RA ? RV x4569 6 d x456A 5 k x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 6 new.data x4566 ? new.next x4567 x456B FP x1234 x4568 RA ? RV x4569 6 d x456A 5 k x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 6 new.data x4566 NULL new.next x4567 x456B FP x1234 x4568 RA ? RV x4569 6 d x456A 5 k x456B head NULL
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 6 new.data x4566 NULL new.next x4567 x456B FP x1234 x4568 RA ? RV x4569 6 d x456A 5 k x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 6 new.data x4566 NULL new.next x4567 x456B FP x1234 x4568 RA 1 RV x4569 6 d x456A 5 k x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP x4565 6 x4566 NULL SP x4567 x456B FP x1234 x4568 RA 1 RV x4569 6 d x456A 5 k x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL SP x4567 x456B FP x1234 x4568 RA 1 RV x4569 6 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1234 SP x4568 RA 1 ? RV x4569 6 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1234 x4568 1 1 1 ? RV SP x4569 6 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1234 x4568 1 ? x4569 6 d SP x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1234 x4568 1 ? x4569 6 x456A 5 k FP, SP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1234 x4568 1 ? x4569 3 d SP x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1234 x4568 1 ? SP x4569 RV 3 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL x4567 x456B x1237 SP x4568 RA 1 ? x4569 RV 3 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 x4566 NULL SP x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4565 6 SP x4566 NULL x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k FP x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 6 new.data x4566 NULL new.next x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 6 new.data x4566 NULL new.next x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k x456B head x4565
rut roh! node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 3 new.data x4566 NULL new.next x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k x456B head x4565
rut roh! node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 3 new.data x4566 x4565 new.next rut roh! x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k x456B head x4565
int add_to_front(int d) { node new; new.data = d; new.next = head; node *head = NULL; int add_to_front(int d) { node new; new.data = d; new.next = head; head = &new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4565 3 new.data x4566 x4565 new.next x4567 x456B FP x1237 x4568 RA 1 ? x4569 RV 3 d x456A 5 k x456B head x4565
The lesson here is.... Be careful about using pointers to variables that are on the stack! In general, it is very dangerous for a global pointer to refer to a local variable 33 33 33 33 33 33 33
Heap An area of memory that is part of your program and is managed by the operating system Your program requests that some memory be allocated, and is given a pointer to that memory (if available) Your program is responsible for releasing it when you're done with it 34 34 34 34 34 34 34
malloc Library function that allocates memory on heap: input: number of bytes to allocate output: pointer to the first address of the memory that was allocated 35 35 35 35 35 35 35
node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3);
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); 5 k FP, SP x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); 6 d SP x456A 5 k FP x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); ? SP x4569 RV 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x1234 SP x4568 RA ? x4569 RV 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); SP x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k FP x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 ? new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 ? new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B head NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 ? new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B x4510 ? head NULL x4511 ?
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B x4510 ? head NULL x4511 ?
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B x4510 6 head NULL x4511 ?
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B x4510 6 head NULL x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1234 x4568 RA ? x4569 RV 6 d x456A 5 k x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1234 x4568 RA 1 x4569 RV 6 d x456A 5 k x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP x4566 x4510 SP x4567 x456B FP x1234 x4568 RA 1 x4569 RV 6 d x456A 5 k x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1234 SP x4568 RA 1 ? x4569 RV 6 d x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1234 x4568 ? 1 SP x4569 RV 6 d x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1234 x4568 1 ? x4569 6 d SP x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1234 x4568 ? 1 x4569 6 x456A 5 k FP, SP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1234 x4568 1 ? x4569 3 d SP x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1234 x4568 ? 1 RV SP x4569 3 d x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 x4567 x456B x1237 RA SP x4568 1 ? RV x4569 3 d x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); x4566 x4510 SP x4567 x456B FP x1237 RA x4568 ? 1 RV x4569 3 d x456A 5 k FP x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 head x4510 x4511 NULL
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4510 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 ? head x4510 x4511 NULL x4501 ?
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4500 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 ? head x4510 x4511 NULL x4501 ?
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4500 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 3 head x4510 x4511 NULL x4501 ?
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4500 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 3 head x4510 x4511 NULL x4501 x4510
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4500 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 3 head x4500 x4511 NULL x4501 x4510
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4500 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 3 head x4500 x4511 NULL x4501 x4510
int add_to_front(int d) { node *new = malloc(sizeof(node)); node *head = NULL; int add_to_front(int d) { node *new = malloc(sizeof(node)); new->data = d; new->next = head; head = new; return 1; } main() { int k; k = 5; add_to_front(6); add_to_front(3); FP, SP x4566 x4500 new x4567 x456B FP x1237 RA x4568 1 ? RV x4569 3 d x456A 5 k x456B x4510 6 x4500 3 head x4500 x4511 NULL x4501 x4510
Today Finding an element (if it exists) in a linked list Implementing a Queue with a linked list Binary Search Trees (time permitting) 68 68 68 68 68 68 68