Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in.

Similar presentations


Presentation on theme: "Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in."— Presentation transcript:

1 cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in ADT - Abstract Data Type

2 cosc237/data structures2 Data Types Simple data type, atomic data type –cannot be broken down –int, float, char structured data type –components can be atomic or structured –rules that define how the components relate to each other –Arrays, structs

3 cosc237/data structures3 C++ Array Domain:Each C++ array consists of 1. A collection of a fixed number of component values each of the same type 2. A set of index values that are nonnegative integers Structure: There is a one-to-one relationship between each index and an array element Operations: Retrieve the value of the array eleemnt asociated with index I Store a value into the array element associated with index i

4 cosc237/data structures4 Data Structures Linear (ordered) –Direct Access Homogeneous components – Array Heterogeneous components – Record –Sequential Access General – List Last-in, first-out – Stack First-in, first-out – Queue Nonlinear (unordered) - Set

5 cosc237/data structures5 Array Components –array elements Access individual elements by – index or subscript Direct access to a component through index Homogeneous components

6 cosc237/data structures6 Array as ADT Domain:Each array consists of 1. A collection of a fixed number of component values each of the same type 2. A set of index values that are nonnegative integers Structure: linear, direct access structure with one- to-one relationship between each index and an array element Operations: ValueAt(i) – retrieve value of array element associated with index i Store(i,v) - Store value v into the array element associated with index i

7 cosc237/data structures7 Record Components – fields Access individual elements by –field name or field identifier Direct access to a component via field name Heterogeneous components

8 cosc237/data structures8 Record as ADT Domain:Each record consists of 1. A collection of a fixed number of component values which may be of different types 2. A set of identifiers (field names) for selecting each component Structure: linear, direct access structure with one- to-one relationship between each field name and a field of the record Operations: ValueAt(fname) – retrieve value of field whose name is fname Store(i,v) - Store value v into the field whose name is fname

9 cosc237/data structures9 List Components –list items or list elements Access individual elements –Sequentially Head or front – first item in the list Tail, back, end – last item in the list Varying length sequential access to a component through implicit list cursor Homogeneous components

10 cosc237/data structures10 List as ADT Domain:Each list consists of 1. A collection of component values each of the same type 2. An implicit list cursor in the range 1 through n + 1, where n is the length of the list Structure: linear, sequential access structure of varying length

11 cosc237/data structures11 List cont'd Operations: Create(); // empty list created Boolean IsEmpty(); Boolean IsFull(); void Reset(); // cursor set to front of list Boolean EndOfList(); void Advance(); // advance cursor to next item ItemType CurrentItem(); //return item at list cursor void InsertBefore(); void InsertAfter(); void Delete();// delete item at list cursor

12 cosc237/data structures12 Lists vs Arrays Advantages of lists –easier to perform insertions & deletions Disadvantage of lists –No direct access

13 cosc237/data structures13 Stacks Restricted list where insertions or deletions occur at one end LIFO – Last-In, First-Out Top – end where insertions or deletion take place Push, Pop, Top Run-time stack

14 cosc237/data structures14 Stack as ADT Domain:Each stack is a collection of component values each of the same type Structure: list maintained in LIFO order so only most recently inserted item is accessible

15 cosc237/data structures15 Stack cont'd Operations: Create(); // empty stack created Boolean IsEmpty(); Boolean IsFull(); void Push(/* in */ ItemType newItem); // newItem is at top of stack ItemType Top(); //return item at top of stack void Pop(); // Top item removed from stack

16 cosc237/data structures16 Queues Restricted list –Insertions occur at the tail of the list - tail –deletions occur at the head - front FIFO – First-In, First-Out Enqueue – appends item to rear of queue Dequeue – removes item from front of queue Front – inspects first item Top – end where insertions or deletion take place Buffered input, printer queue

17 cosc237/data structures17 Queue as ADT Domain:Each queue is a collection of component values each of the same type Structure: list maintained in FIFO order so insertions take place at the rear and deletions take place at the front

18 cosc237/data structures18 Queue cont'd Operations: Create(); // empty queue created Boolean IsEmpty(); Boolean IsFull(); void Enqueue(/* in */ ItemType newItem); // newItem is at rear of queue ItemType Front(); //return item at front of queue void Dequeue(); // front item removed from queue


Download ppt "Cosc237/data structures1 Data Types Every data type has two characteristics: 1.Domain - set of all possible values 2.set of allowable operations Built-in."

Similar presentations


Ads by Google