CS 310 Unit 8 Elementary Data Structures

CS 310 Unit 8 Elementary Data Structures - CS 310 Unit 8...

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

View Full Document Right Arrow Icon
CS 310 Unit 8 Elementary Data Structures Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato Spring 2008
Background image of page 1

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

View Full DocumentRight Arrow Icon
CS 310 Unit 8 Elementary Data Structures Objectives Dynamic Sets Stacks Queues Linked Lists Sentinel Linked Lists Implementing Rooted Trees as Multiply- linked Lists Text, Chapter 10
Background image of page 2
Dynamic Sets Sets may be dynamic or static Many mathematical sets, e.g., the set of real numbers, the set of integers, the set of prime numbers, etc. are static. Many of the sets on which algorithms operate are dynamic The simplest dynamic sets are called dictionaries . Dictionaries support the following operations: element *Search(set S, key k); // returns null if no member has key k bool Insert(set S, element *x); // returns true if successful; false, otherwise bool Delete(set S, element *x); // returns true if successful; false, otherwise
Background image of page 3

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

View Full DocumentRight Arrow Icon
Dynamic Sets More complex dynamic sets include stacks, queues, and lists. Operations which may be supported by more dynamic sets (in addition to those supported by dictionaries) depending upon their specification include the following: elemType *Minimum(set S); // returns pointer to minimum key element // or NULL if set is empty elemType *Maximum(set S); // returns pointer to minimum key element // or NULL if set is empty elemType *Next(set S, elemType *x); // returns pointer to next element // or NULL if set is empty or x points to last elemType *Previous(set S, elemType *x); // returns pointer to previous element // or NULL if set is empty or x points to first
Background image of page 4
Stacks Semantics LIFO (Last-In-First-Out) buffer Data structure: depends on implementation Operations: int sizeOf(stackType); int limitOf(stackType); // if static data structure bool isEmpty(stackType); bool isFull(stackType); bool push(stackType, * elemType); int pop(stackType);
Background image of page 5

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

View Full DocumentRight Arrow Icon
Example Stack Implementation Data structure: n-element array with parameter top; const int n = {size of array} elemType S[n], top = 0; Operations: int sizeOf(stackType S) {return top;} int limitOf(stackType S){return n; } bool isEmpty(stackType S) {return top == 0;} bool isFull(stackType S) {return n == top;} bool push(stackType S, elemType *element) { if(!isFull()) { S[top++] = *element; return true; } else return false; int pop(stackType S) { if(!isEmpty()) return --top; else return -1; }
Background image of page 6
Queues Semantics FIFO (First-In-First-Out) buffer Data structure: depends on implementation Operations: int sizeOf(queueType); int limitOf(queueType); // if static data structure bool isEmpty(queueType); bool isFull(queueType); bool enque(queueType, *elemType); int deque(queueType);
Background image of page 7

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

View Full DocumentRight Arrow Icon
Example Queue Implementation Data structure: n-element circular array, parameters head, tail; const int n = {size of array} elemType Q[n]; int head = 0, tail = 0, size = 0; Operations: int sizeOf(queueType Q) {return size;} int limitOf(queueType Q){return n;} bool isEmpty(queueType Q) {return size == 0;} bool isFull(queueType Q) {return n == size;} bool push(queueType Q, elemType element) { if(!isFull()) { Q[++tail] = element; size++; return true; } else return false; } elemType pop(queueType Q) { if(!isEmpty()){ size--; return tail++; } else return -1; }
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 06/09/2008 for the course CS 310 taught by Professor Furmanhaddix during the Spring '08 term at Minnesota State University, Mankato.

Page1 / 34

CS 310 Unit 8 Elementary Data Structures - CS 310 Unit 8...

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

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