Download presentation
Presentation is loading. Please wait.
1
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
2
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
3
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
4
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
5
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
6
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
7
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
8
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
9
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
10
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
11
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
12
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
13
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
14
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
15
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
16
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
17
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
18
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
19
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
20
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
21
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
22
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
23
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
24
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
25
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
26
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
27
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
28
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
29
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
30
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
31
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
32
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
33
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
34
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
35
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
36
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);
37
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
38
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
39
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
40
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
41
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
42
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
43
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
44
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 ?
45
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 ?
46
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 ?
47
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
48
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
49
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
50
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
51
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
52
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
53
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
54
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
55
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
56
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
57
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
58
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
59
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
60
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
61
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 ?
62
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 ?
63
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 ?
64
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
65
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
66
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
67
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
68
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.