{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture16

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

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

Introduction to Low-Level Programming Concepts CMSC 212 Lecture 16 1 CMSC 212 October 22, 2009 Last time circle6 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 searching in a binary search tree 2 CMSC 212 Reading circle6 Read Chapter 13 in Reek (Pointers on C) 3 CMSC 212 Chapter 12, Using Structures and Pointers (Pointers and Data Structures), con't. 4 CMSC 212

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

View Full Document
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 circle6 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 circle6 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
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; new->out_edges= NULL; 9 CMSC 212 circle6 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.

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}