CS 310 Unit 8 Elementary Data Structures

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

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

CS 310 Unit 8 Elementary Data Structures Furman Haddix Ph.D. Assistant Professor Minnesota State University, Mankato Spring 2008

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

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

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

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

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

View Full Document
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; }
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);

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

View Full Document
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; }
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
Ask a homework question - tutors are online