*This preview shows
pages
1–7. Sign up
to
view the full content.*

This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*This
** preview**
has intentionally

**sections.**

*blurred***to view the full version.**

*Sign up*
**Unformatted text preview: **Introduction to Computer Programming November 28, 2008 CSC180 Fall 2008, University of Toronto Review • Pointers and pointer arithmetic, see pointer arithmetic.pdf CSC180 Fall 2008, University of Toronto 1 Linked lists • A node: struct node { int data; struct node *next; struct node *prev; }; • Deletion: p->next->prev = p->prev; p->prev->next = p->next; free(p); CSC180 Fall 2008, University of Toronto 2 • Insertion: p->next = q->next; q->next->prev = p; q->next = p; p->prev = q; Or, p->next = q->next; p->prev = q; p->next->prev = p; p->prev->next = p; • Exercise: consider special cases for deletion and insertion. CSC180 Fall 2008, University of Toronto 3 Pass by value • Change variables of basic types #include <stdio.h> void clear(int n) { n = 0.0; } void clear2(int *n) { *n = 0.0; } int main() { CSC180 Fall 2008, University of Toronto 4 int x = 999; clear(x); printf("%d\n", x); clear2(&x); printf("%d\n", x); return 0; } • Change pointer variables #include <stdio.h> void clear(int *p) { p = NULL; } void clear2(int **p) CSC180 Fall 2008, University of Toronto 5 {...

View
Full
Document