Queues - UAH CPE 212 Fundamentals of Software Engineering...

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

View Full Document Right Arrow Icon
UAH CPE 212 Fundamentals of Software Engineering Agenda Class 13 Queues Queues Key Concepts
Background image of page 1

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

View Full DocumentRight Arrow Icon
UAH CPE 212 Today Last Time Stacks LIFO, push, pop This Time Queue Concept Queue Implementations Queue Application
Background image of page 2
UAH CPE 212 Queues Abstract Concept Can have heterogeneous or homogeneous queues Often called First In First Out (FIFO) Uses: Message handling Task handling, e.g printers Key Operations enque(insert) deque(remove) Enque Deque 1 2 3 4 Tail Head
Background image of page 3

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

View Full DocumentRight Arrow Icon
UAH CPE 212 Queues Array Implementations Advantages: performance Disadvantage: Resizing the queue Enque Deque 1 2 3 4 Tail Head Method 1 Remove and Slide Method 2 Chasing Pointers Enque Deque 1 2 Next Ptr Head Ptr Make this into a circular queue to avoid running out of space
Background image of page 4
UAH CPE 212 Queues Linked List Implementation Advantages: Resizing the queue Disadvantage: performance Head Remove at head Insert at Tail Tail Singly or Doubly Linked? Head Tail
Background image of page 5

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

View Full DocumentRight Arrow Icon
UAH CPE 212 Queue Implementation #ifndef QUEUE1_H // Prevent duplicate definition #define QUEUE1_H #include <stdlib.h> // Provides size_t template <class Item> class Queue { public: // MEMBER CONSTANTS -- See page 87 for a better alternative enum { CAPACITY = 30 }; // CONSTRUCTOR Queue( ); // MODIFICATION MEMBER FUNCTIONS void insert(const Item& entry); Item get_front( ); // CONSTANT MEMBER FUNCTIONS size_t size( ) const { return count; } bool is_empty( ) const { return (count == 0); } private: Item data[CAPACITY]; // Partially-filled array size_t front; // Index of item at front of the queue size_t rear; // Index of item at rear of the queue size_t count; // Total number of items in the queue // HELPER MEMBER FUNCTION size_t next_index(size_t i) const { return (i+1) % CAPACITY; } }; #include "queue1.template" // Include the implementation #endif
Background image of page 6
UAH CPE 212 Queue Implementation 2 #include <assert.h> // Provides assert #include <stdlib.h> // Provides size_t template <class Item> Queue<Item>::Queue( ) { count = 0; front = 0; rear = CAPACITY - 1; } template <class Item> // Library facilities used: assert.h
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 / 18

Queues - UAH CPE 212 Fundamentals of Software Engineering...

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