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); // if static data structure 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); // if static data structure 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.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern