1 cs2303: systems programming concepts class 14 data structures: defining using implementing...
Post on 21-Dec-2015
214 views
TRANSCRIPT
1
CS2303: Systems Programming Concepts
Class 14Data Structures:
DefiningUsing
ImplementingCopyright 2005-2008, Michael J. Ciaraldi
2
Data Structures
You may have used some: Stack Queue Linked list Tree
We will learn how to make them.
3
Data Structures
We will learn how to make them. Why? Not always available. Might have to implement. Better understanding.
Pick most appropriate.
Built-in not appropriate.E.g. kernel, time-critical.
4
Defining and UsingData Structures
5
StackGets it name from where?
And is it appropriate?Policy: LIFO
Where else is that used? Top
Operations: push() pop() peek() isEmpty()
6
Conceptual Stack: push-down
One entry in stack
Push Push3 entries in stack
7
Conceptual Stack: pop up
3 entries in stack
Pop PopPop causes empty stack
8
Practical Stack
One entry in stack
Push Push Push
Sta
ck poin
ter
9
Stack Options
Growth Up? Down?
Stack pointer points to: “Top” of stack? Next free cell?
Types of elements restricted/preserved?
10
Stack Warnings
How to handle stack overflow?How to handle stack underflow?What is “handle”?
Detect Stack effect Return value Signal error condition
11
Queue
Gets it name from where? And is it appropriate?
Policy: FIFO Where else is that used? Add at tail, remove at head.
Operations: enqueue() dequeue() peek() isEmpty()
12
Conceptual Queue
One entry in queue
Enqueue Enqueue Enqueue
13
Conceptual Queue
3 entries in queue
Dequeue DequeueDequeue causes
empty queue
14
Practical Queue
Tail pointerHead pointer
15
Queue Options
Fixed maximum size?Priority?Add/delete at both ends?
Deque = double-ended queue.Types of elements
restricted/preserved?
16
Queue Warnings
How to handle wraparound?How to handle queue overflow?How to handle queue underflow?What is “handle”?
Detect Queue effect Return value Signal error condition
17
Data StructureImplementation
18
Implementation
Alternatives: Object-oriented Not
19
Implementation
Object-oriented Each stack or queue is a separate
object. Fields: Stack data area, size, pointer. Methods: push(), pop(), etc.
20
Implementation
Not Object-oriented Series of functions: create(), push(),
pop(), etc. Need identifier if more than one. Where to store specs? Risky, but done: just a stack pointer.
21
Next Time
More data structures: Implementation, list, tree…