CS 310 Unit 8 Elementary Data Structures

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

Info icon This 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
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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); // if static data structure bool push(stackType, * elemType); int pop(stackType);
Image of page 5

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

View Full Document Right 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; }
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); // if static data structure bool enque(queueType, *elemType); int deque(queueType);
Image of page 7

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

View Full Document Right 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; }
Image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    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.

    Student Picture

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

  • Left Quote Icon

    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.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    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.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern