Bank

Only available on StudyMode
  • Download(s) : 64
  • Published : May 3, 2013
Open Document
Text Preview
Lab Session # 08

Implementing Queue ADT using Circular Array

Laboratory Manual Data Structures using C++ Lab Session # 08

Implementing Queue ADT using Circular Array

© Electrical Engineering Department UET Lahore

Designed by: Waseem Arshad

Lab Session # 08

Implementing Queue ADT using Circular Array

Lab Objectives In this lab we will learn implementation of queue data structure using circular array.

Queue Data Structure
Like stack Queues are lists. With a queue, however, insertion is done at one end, whereas deletion is preformed at the other end. A Queue always maintains last in first out (LIFO) structure. The basic operation on a queue are enqueue, which inserts an element at the end of the list (called the rear), and dequeue, which deletes (and returns) the element at the start of the list (known as the front).

Implementation using Circular Array
Like stack, queue can also be implemented using linked list, but here we will discuss a more simple and memory efficient implementation of Queue ADT (you should be able to write linked list implementation). Given below is an implementation that uses a circular array to implement Queue ADT, please consult your lab instructor to understand the implementation. QueueAr.h #ifndef QUEUEAR_H #define QUEUEAR_H #include using std::vector; //#include "dsexceptions.h" // // // // // // // // // // // // // Queue class -- array implementation CONSTRUCTION: with or without a capacity; default is 10 ******************PUBLIC OPERATIONS********************* void enqueue( x ) --> Insert x void dequeue( ) --> Return and remove least recently inserted item Object getFront( ) --> Return least recently inserted item bool isEmpty( ) --> Return true if empty; else false bool isFull( ) --> Return true if full; else false void makeEmpty( ) --> Remove all items ******************ERRORS******************************** Overflow and Underflow thrown as needed

template class Queue { public: explicit Queue( int...
tracking img