lecture16 - Last time Introduction to Low-Level Programming...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Introduction to Low-Level Programming Concepts CMSC 212 ecture 16 1 CMSC 212 Lecture 16 October 22, 2009 Last time c Chapter 12, Using structures and pointers (pointers and data structures) – searching, inserting, and deleting with a singly-linked list – deleting from a doubly-linked list – designing linked list operations and inserting into a doubly- linked list earching in a binary search tree 2 CMSC 212 – searching in a binary search tree Reading c Read Chapter 13 in Reek (Pointers on C) 3 CMSC 212 Chapter 12, Using Structures and Pointers (Pointers and Data 4 CMSC 212 Structures), con't.
Background image of page 1

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

View Full DocumentRight Arrow Icon
A recursive function to find a value in a binary search tree int lookup(Node *curr, int value) { if (curr == NULL) return 0; else if (curr->data == value) return 1; 5 CMSC 212 else if (curr->data > value) return lookup(curr->left, value); else return lookup(curr->right, value); } Inserting into a binary search tree int insert(Node **root, int value) { Node *new= NULL; if (*root == NULL) { new= malloc(sizeof(*new)); if (new == NULL) return 0; 6 CMSC 212 new->data= value; new->left= new->right= NULL; *root= new; return 1; } if ((*root)->data > value) return insert(&((*root)->left), value); else return insert(&((*root)->right), value); } Directed graphs c A graph: – consists of nodes connected by edges or arcs – an arbitrary number of nodes can be present – each node can have an arbitrary number of outgoing edges c Example declarations: struct node; / * partial declaration */ 7 CMSC 212 typedef struct edge { struct node *destination_node; struct edge *next; } Edge; typedef struct node { Edge *out_edges; int node_number; } Node; Graphs node key 5 7 8 CMSC 212 edge NULL NULL NULL 14
Background image of page 2
Creating a node in a graph Node *add_node(int nbr) { Node *new; new= malloc(sizeof(*new)); if (new == NULL) return NULL; new->node_number= nbr; 9 CMSC 212 c This Node needs to be stored in some type of data structure: – an array of Node s – a linked list of Node s – a tree of Node s – etc. new->out_edges= NULL;
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/23/2009 for the course CMSC 212 taught by Professor Staff during the Spring '08 term at Maryland.

Page1 / 6

lecture16 - Last time Introduction to Low-Level Programming...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online