lec09 - CSE 12 The Queue Abstract Data Type The Queue ADT...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
09-1/30 The Queue ADT Designing a test plan for Queue The Adapter pattern again Implementing Queue using a linked list Implementing Queue using an array Circular arrays Time costs of Queue implementations CSE 12 The Queue Abstract Data Type
Background image of page 1

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

View Full DocumentRight Arrow Icon
09-2/30 Introduction Queue : a F irst- I n- F irst- O ut ( FIFO ) data structure the first item put into the stack will be the first item to be taken out of it Values: a sequence of data items of type T Operations: enqueue(T) T dequeue() T peek() boolean isEmpty() int size() clear() these are the essential ones!
Background image of page 2
09-3/30 Examples of Queue usage Operating systems schedulers: processes can be placed in a ready queue awaiting their turn to use the processor Print spoolers: print jobs on a first-come-first-served basis Network packet buffering: packets arriving on the input port of a router will be queued up on one of the router’s output port for the next hop Simulations of any queue-like behavior (e.g., planes on a runway, customers in a checkout line)
Background image of page 3

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

View Full DocumentRight Arrow Icon
09-4/30 Queue Properties and Attributes Properties 1.Queues are FIFO structures. All additions are done at the rear and all deletions at the front 2.The front always refers to the first element in the queue 3.The rear always refers to the position where the next element is to be added to the queue 4.The queue has a fixed upper bound (capacity) on the number of elements it can store Attributes capacity : The maximum number of elements that can be in the queue size : The number of elements in the queue: 0 ≤ size ≤ capacity front : The first element of the queue, or a null value not part of the queue when the queue is empty rear : The position in the queue where the next element is to be inserted, or a null value not part of the queue if the queue is full A Queue could be “boundless”, but this example has a fixed capacity. ..
Background image of page 4
A typical queue Head or Front of the Queue Tail or Back of the Queue
Background image of page 5

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

View Full DocumentRight Arrow Icon
09-6/30 Queue Operations Note features needed to accommodate an upper bound on the collection’s capacity Queue() pre-condition: none responsibilities: constructor - initialize the queue attributes post-condition: size is set to 0 capacity is set to DEFAULT_CAPACITY front refers to a null value (not part of the queue) rear refers the position where the first insertion will be made returns: nothing Queue( int maxElements ) pre-condition: maxElements > 0 responsibilities: constructor — initialize the queue attributes post-condition: size is set to 0 capacity is set to maxElements front refers to a null value rear refers to the position where the first insertion will be made returns: nothing throws: invalid argument exception if pre-condition is not met
Background image of page 6
09-7/30 Queue Operations: enqueue() enqueue( T element ) pre-condition:isFull() is false responsibilities: insert element at the rear of the queue post-condition: element is placed at the rear of the queue size is incremented by 1 rear is advanced to the position where the next element will be inserted,
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 35

lec09 - CSE 12 The Queue Abstract Data Type The Queue ADT...

This preview shows document pages 1 - 8. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online