1 Lab guide 11 C Data Structures Review
1 Lab guide #11 C Data Structures Review & Lab assignments 2007 Pearson Education, Inc. All rights reserved.
2 Key points § Self-Referential Structure § Dynamic Memory Allocation § Dynamic data structures – – Linked lists Stacks Queues Trees 2007 Pearson Education, Inc. All rights reserved.
3 Self-Referential Structures § Self-referential structures: – Structure contains a pointer to a structure of the same type struct node { int data; struct node *next. Ptr; } § next. Ptr – Points to an object of type node – Referred to as a link 2007 Pearson Education, Inc. All rights reserved.
4 Dynamic Memory Allocation § Dynamic memory allocation – malloc (): Obtain memory for a new structure - Takes number of bytes to allocate - Return a void * pointer or Null - Example: new. Ptr = malloc( sizeof( struct node ) ); – free (): Release memory - Deallocates memory allocated by malloc - Takes a pointer as an argument - free ( new. Ptr ); 2007 Pearson Education, Inc. All rights reserved.
5 Dynamic data structures § Dynamic data structures – Data structures that grow and shrink during execution § Linked lists – Allow insertions and removals anywhere – Can be used when the number of data element is unpredictable § Stacks – Allow insertions and removals only at top of stack – Rule: Last in first out § Queues – Allow insertions at the back and removals from the front – Rule: First in, first out § Binary trees – High-speed searching and sorting of data and efficient elimination of duplicate data items 2007 Pearson Education, Inc. All rights reserved.
6 Lab assignments § Fig 12. 3 § Fig 12. 8 § Fig 12. 13 § Fig 12. 19 2007 Pearson Education, Inc. All rights reserved.
- Slides: 6