{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

LEC20081128

# LEC20081128 - Introduction to Computer Programming CSC180...

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

Introduction to Computer Programming November 28, 2008 CSC180 Fall 2008, University of Toronto

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
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
{ *p = NULL; } int main() { int n, *p; p = &n; clear(p); printf("%p\n", p); clear2(&p); printf("%p\n", p); return 0; } Change variables of compound types #include <stdio.h> CSC180 Fall 2008, University of Toronto 6

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
#include <string.h>
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern