Preview

Bank

Satisfactory Essays
Open Document
Open Document
469 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Bank
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

You May Also Find These Documents Helpful

  • Satisfactory Essays

    NT1230 Lab 10

    • 1546 Words
    • 8 Pages

    6. In the Instances of selected object list, select 0, and then click Add. The Queue Length counter appears in the Added counters list.…

    • 1546 Words
    • 8 Pages
    Satisfactory Essays
  • Good Essays

    Nt1420 Unit 6

    • 1145 Words
    • 5 Pages

    INSTRUCTIONS: 1. THERE ARE SIX (6) QUESTIONS IN THIS PAPER. 2. ANSWER FIVE (5) QUESTIONS ONLY. Question 1 Arrays are used when storing a large number of values. You are required to create an array named a and answer the following questions regarding array manipulation. a. Write a method fillRandom(int[] a, int min, int max), fill the array a with a random integer value. (Note: Math.random() returns a double in the range of 0.0 and 1.0, therefore it is cast to an integer number, between the minimum and maximum value). [6 marks] b. Write the Bubble sort method to sort array a into descending order. [10 marks] c. In the quicksort, an algorithm an element is chosen from the unsorted list. This element is called the…

    • 1145 Words
    • 5 Pages
    Good Essays
  • Powerful Essays

    Nt1330 Unit 1 Research Paper

    • 4285 Words
    • 18 Pages

    Each character requires one byte as it is usually stored as an ASCII character. Notice that a digit such as 8 could be held as either a character, an integer or even a real. If any calculations are going to take place on the value then it should be held as either an integer or a real. If the calculation will never result in it being extremely large or gaining decimal places then an integer should be used.…

    • 4285 Words
    • 18 Pages
    Powerful Essays
  • Good Essays

    1. Is a recursive data structure, because it contains a pointer to a smaller object of the same type. For that reason, many operations on singly linked linear list (such as merging two lists, or enumerating the elements in reverse order) often have very simple recursive algorithms, much simpler than any solution using iterative commands.…

    • 606 Words
    • 3 Pages
    Good Essays
  • Better Essays

    | Access to records in a Sequential file is serial. To reach a particular record, all the preceding records must be read.As we observed when the topic was introduced earlier in the course, the organization of an unordered Sequential file means it is only practical to read records from the file and add records to the end of the file (OPEN..EXTEND). It is not practical to delete or update records.While it is possible to delete, update and insert records in an ordered Sequential file, these operations have some drawbacks.…

    • 2969 Words
    • 12 Pages
    Better Essays
  • Good Essays

    #include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> #include<ctype.h> #define max 30 struct stack { char opstack[max]; int tos; }; void push(struct stack *,char); char pop(struct stack *); int prece(char ); void main() { int i,j=0,k,l; char ch,infix[max], postfix[max]; stack pq; pq.tos=-1; A: clrscr(); printf("\nEnter the infix string:\t"); gets(infix); for(i=0;infix[i]!='\0';i++) { if (infix[i]=='(') push(&pq,infix[i]); else if (isalpha(infix[i])) { postfix[j]=infix[i]; j++; } else if (infix[i]=='+'||infix[i]=='-'||infix[i]=='/'||infix[i]=='$'||infix[i]=='*') { if(pq.tos!=-1 && prece(pq.opstack[pq.tos])>=prece(infix[i])) {ch=pop(&pq); postfix[j]=ch; j++; } push(&pq,infix[i]); } else if (infix[i]==')')…

    • 279 Words
    • 2 Pages
    Good Essays
  • Good Essays

    Objective:To learn about Insertion sort algorithm,know how it works and use it in real life.…

    • 470 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    This assignment has three purposes. The first is to give you experience with representations based on list structures and with methods for list processing that manipulate them. To complete the exercise, you must implement a system that stores information using embedded lists and that alters these structures through a series of operations.…

    • 1466 Words
    • 6 Pages
    Powerful Essays
  • Powerful Essays

    Linked List Basics

    • 8040 Words
    • 33 Pages

    Abstract This document introduces the basic structures and techniques for building linked lists with a mixture of explanations, drawings, sample code, and exercises. The material is useful if you want to understand linked lists or if you want to see a realistic, applied example of pointer-intensive code. A separate document, Linked List Problems (http://cslibrary.stanford.edu/105/), presents 18 practice problems covering a wide range of difficulty. Linked lists are useful to study for two reasons. Most obviously, linked lists are a data structure which you may want to use in real programs. Seeing the strengths and weaknesses of linked lists will give you an appreciation of the some of the time, space, and code issues which are useful to thinking about any data structures in general. Somewhat less obviously, linked lists are great way to learn about pointers. In fact, you may never use a linked list in a real program, but you are certain to use lots of pointers. Linked list problems are a nice combination of algorithms and pointer manipulation. Traditionally, linked lists have been the domain where beginning programmers get the practice to really understand pointers. Audience The article assumes a basic understanding of programming and pointers. The article uses C syntax for its examples where necessary, but the explanations avoid C specifics as much as possible — really the discussion is oriented towards the important concepts of pointer manipulation and linked list algorithms. Other Resources • Link List Problems (http://cslibrary.stanford.edu/105/) Lots of linked list problems, with explanations, answers, and drawings. The "problems" article is a companion to this "explanation" article. • Pointers and Memory (http://cslibrary.stanford.edu/102/) Explains all about how pointers and memory work. You need some understanding of pointers and memory before you can understand linked lists. •…

    • 8040 Words
    • 33 Pages
    Powerful Essays
  • Good Essays

    Logistics, Bin Packing

    • 409 Words
    • 2 Pages

    They coded algorithms in C++ programming language and solved with same computer. After this information they explain the methodologies. For the mathematical programming with column generation technique, they made five assumptions and give notations with the mathematical model. They develop the following procedure for the column generation.…

    • 409 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    Revision Notes Computer

    • 271 Words
    • 2 Pages

    [Structure, Class and Object, Constructor and Destructor, Inheritance, File Handling, Pointer, Array, Data Structure and class 11th revision tour]…

    • 271 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Apply appropriate fundamental data structures and abstract data types (ADT) such as bags, lists, stacks, queues etc and heaps: min/max heap, min-max heap and some advance hierarchal data structures like B-Trees: 2-3 tree, 2-3-4 tree and hash tables, and graphs in problem solving.…

    • 908 Words
    • 7 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Intro

    • 7464 Words
    • 30 Pages

    Introduction • Arrays are used for the storage of homogeneous data. • Hence we have user defined data types like structures, unions, and enumerations to store data with different types. • One of the similarities between arrays and structures is that both of them contain a finite number of elements. Thus, array types and structure types are collectively known as aggregate types. • Unions are similar to structures in all aspects except the manner in which their constituent elements are stored. • In structures, separate memory is allocated to each element, while in unions all the elements share the same memory. • Enumerations help you in defining a data type whose objects can take a limited set of values.…

    • 7464 Words
    • 30 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Buffers are often used in conjunction with I/O to hardware, such as disk drives, sending or receiving data to or from a network, or playing sound on a speaker. A line to a rollercoaster in an amusement park shares many similarities. People who ride the coaster come in at an unknown and often variable pace, but the roller coaster will be able to load people in bursts (as a coaster arrives and is loaded). The queue area acts as a buffer—a temporary space where those wishing to ride wait until the ride is available. Buffers are usually used in a FIFO (first in, first out) method, outputting data in the order it arrived.…

    • 559 Words
    • 3 Pages
    Satisfactory Essays
  • Powerful Essays

    Data structures

    • 7448 Words
    • 47 Pages

    2. Ellis Horowitz, Sartaj Sahni, & Susan Anderson Freed, “Fundamentals of Data Structures in C”, University Press, 2nd Edition, 2008 (Sections 3.5, 4.7, 6.1, 6.2.1, 6.2.2, 6.3.1, 6.3.2)…

    • 7448 Words
    • 47 Pages
    Powerful Essays

Related Topics