SlideShare a Scribd company logo
Queue



Prepared by:
      Eng. Ahmed & Mohamed Taha
Agenda


 Introduction to Queue.

 How Queue works.

 Operations performed on Queue.

 Queue Implementation.
Introduction to Queue


 Queue is an ordered collection of items in which new data
  items are added at the end, or tail, of the queue while
  other data are removed from the front, or head, of the
  queue. For this reason, a queue is referred to as a FIFO
  structure (First-In First-Out)

 The main primitive operations of a queue are known as:

      Add adds a new node
      Remove removes a node

 Additional primitives can be defined:

      IsEmpty: reports whether the queue is empty
      IsFull: reports whether the queue is full
      Initialize: creates/initializes the queue
      Destroy: deletes the contents of the queue    (may   be
       implemented by re-initializing the queue)
Introduction to Queue




Company Logo
Introduction to Queue




Company Logo
Introduction to Queue




Company Logo
Queue Implementation
using Object Oriented
    Programming
Queue Implementation                     using Array




#include <iostream.h>
#include <conio.h>
#include <stdlib.h>

#define max_size 100
#define TRUE 1
#define FALSE 0
typedef int boolean;

/************************************/
Class queue
{
  private:
          int items[max_size];
          int front,rear;
  public:

};
Queue Implementation                         using address




     /////////////////////////////funcions
     // Initialize Function
     void queue:: queue()
     {
                  front=0;
                  rear=-1;
     }

// Is_empty Function
boolean queue:: is_empty()
{
         if (rear < front)
                   return TRUE;
         return FALSE;
}
Queue Implementation                            using address




// Insert Function
void queue:: insert(int item)
{
           if (rear == max_size-1)
           {
                     cout<<"Queue is Overflow";
                     exit(0);
           }
           else
           rear++;
           items[rear]=item;
}
Queue Implementation                           using address




// Remove Function
int queue:: remove()
{
         if (is_empty())
         {
                   cout<<"Queue is underflow";
                   return -1;
         }
         int item=items[front];
         front++;
         return item;
}
Queue Implementation                                        using address




// Print all elements Funcion
void queue:: print_all_elements ()
{
           cout<<"the current items of the queue are:"<<endl;
           for(int i=front;i<=rear;i++)
                     cout<<items[i]<<" ";
           cout<<endl;
}
Queue Implementation      using address




void main()
{
         clrscr();
         queue q;
         q.insert(1);
         q.insert(2);
         q.insert(3);
         q.insert(4);
         q.print_all_elements(q);
         int val=q.remove();
         val=q.remove();
         q.print_all_elements();
         q.insert(5);
         q.insert(6);
         q.print_all_elements();
         getch();

}
Ad

More Related Content

What's hot (20)

Function
FunctionFunction
Function
venkatme83
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
Muhammad Hammad Waseem
 
The Big Three
The Big ThreeThe Big Three
The Big Three
Roman Okolovich
 
Lecture05
Lecture05Lecture05
Lecture05
elearning_portal
 
Faster Python, FOSDEM
Faster Python, FOSDEMFaster Python, FOSDEM
Faster Python, FOSDEM
Victor Stinner
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
Teerawat Issariyakul
 
Chapter iii(advance function)
Chapter iii(advance function)Chapter iii(advance function)
Chapter iii(advance function)
Chhom Karath
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
Mekk Mhmd
 
Team 6
Team 6Team 6
Team 6
Sathasivam Rangasamy
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
NamanKikani
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
Swarup Boro
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
Divya Kumari
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Intoduction to dynamic memory allocation
Intoduction to dynamic memory allocationIntoduction to dynamic memory allocation
Intoduction to dynamic memory allocation
Utsav276
 
Heap sort &amp; bubble sort
Heap sort &amp; bubble sortHeap sort &amp; bubble sort
Heap sort &amp; bubble sort
Shanmuga Raju
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
Divya Kumari
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
Roman Rodomansky
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
rkaippully
 
Queue
QueueQueue
Queue
Nabeel Ahsen
 
Lab 1
Lab 1Lab 1
Lab 1
rimshailyas1
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
Teerawat Issariyakul
 
Chapter iii(advance function)
Chapter iii(advance function)Chapter iii(advance function)
Chapter iii(advance function)
Chhom Karath
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
Mekk Mhmd
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
NamanKikani
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
Swarup Boro
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
Divya Kumari
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Intoduction to dynamic memory allocation
Intoduction to dynamic memory allocationIntoduction to dynamic memory allocation
Intoduction to dynamic memory allocation
Utsav276
 
Heap sort &amp; bubble sort
Heap sort &amp; bubble sortHeap sort &amp; bubble sort
Heap sort &amp; bubble sort
Shanmuga Raju
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
Divya Kumari
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
Roman Rodomansky
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
rkaippully
 

Similar to Queue oop (20)

Data Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptxData Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptx
RashidFaridChishti
 
The presention is about the queue data structure
The presention is about the queue data structureThe presention is about the queue data structure
The presention is about the queue data structure
gaurav77712
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
Dabbal Singh Mahara
 
Qprgs
QprgsQprgs
Qprgs
Ssankett Negi
 
week-16x
week-16xweek-16x
week-16x
KITE www.kitecolleges.com
 
Queues_0748555555555555555555555526.pptx
Queues_0748555555555555555555555526.pptxQueues_0748555555555555555555555526.pptx
Queues_0748555555555555555555555526.pptx
nailapp2023
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
singhprpg
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
Ain-ul-Moiz Khawaja
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
05 queues
05 queues05 queues
05 queues
Rajan Gautam
 
Lec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees Another implementation of Queues using ArraysLec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees Another implementation of Queues using Arrays
Anil Yadav
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Katang Isip
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 
Polynomialmotilalanehrunationalinstitute.pdf
Polynomialmotilalanehrunationalinstitute.pdfPolynomialmotilalanehrunationalinstitute.pdf
Polynomialmotilalanehrunationalinstitute.pdf
yugpadhiyar2006
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
btechsmartclass
 
Data Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptxData Structures and Agorithm: DS 09 Queue.pptx
Data Structures and Agorithm: DS 09 Queue.pptx
RashidFaridChishti
 
The presention is about the queue data structure
The presention is about the queue data structureThe presention is about the queue data structure
The presention is about the queue data structure
gaurav77712
 
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
Queues_0748555555555555555555555526.pptx
Queues_0748555555555555555555555526.pptxQueues_0748555555555555555555555526.pptx
Queues_0748555555555555555555555526.pptx
nailapp2023
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
singhprpg
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
Rajkiran Nadar
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
NuraMohamed9
 
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDYDATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Malikireddy Bramhananda Reddy
 
Lec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees Another implementation of Queues using ArraysLec-12, 13 Quees Another implementation of Queues using Arrays
Lec-12, 13 Quees Another implementation of Queues using Arrays
Anil Yadav
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
CBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical fileCBSE Class XII Comp sc practical file
CBSE Class XII Comp sc practical file
Pranav Ghildiyal
 
1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf1- The design of a singly-linked list below is a picture of the functi (1).pdf
1- The design of a singly-linked list below is a picture of the functi (1).pdf
afgt2012
 
Polynomialmotilalanehrunationalinstitute.pdf
Polynomialmotilalanehrunationalinstitute.pdfPolynomialmotilalanehrunationalinstitute.pdf
Polynomialmotilalanehrunationalinstitute.pdf
yugpadhiyar2006
 
Ad

Queue oop

  • 1. Queue Prepared by: Eng. Ahmed & Mohamed Taha
  • 2. Agenda  Introduction to Queue.  How Queue works.  Operations performed on Queue.  Queue Implementation.
  • 3. Introduction to Queue  Queue is an ordered collection of items in which new data items are added at the end, or tail, of the queue while other data are removed from the front, or head, of the queue. For this reason, a queue is referred to as a FIFO structure (First-In First-Out)  The main primitive operations of a queue are known as:  Add adds a new node  Remove removes a node  Additional primitives can be defined:  IsEmpty: reports whether the queue is empty  IsFull: reports whether the queue is full  Initialize: creates/initializes the queue  Destroy: deletes the contents of the queue (may be implemented by re-initializing the queue)
  • 7. Queue Implementation using Object Oriented Programming
  • 8. Queue Implementation using Array #include <iostream.h> #include <conio.h> #include <stdlib.h> #define max_size 100 #define TRUE 1 #define FALSE 0 typedef int boolean; /************************************/ Class queue { private: int items[max_size]; int front,rear; public: };
  • 9. Queue Implementation using address /////////////////////////////funcions // Initialize Function void queue:: queue() { front=0; rear=-1; } // Is_empty Function boolean queue:: is_empty() { if (rear < front) return TRUE; return FALSE; }
  • 10. Queue Implementation using address // Insert Function void queue:: insert(int item) { if (rear == max_size-1) { cout<<"Queue is Overflow"; exit(0); } else rear++; items[rear]=item; }
  • 11. Queue Implementation using address // Remove Function int queue:: remove() { if (is_empty()) { cout<<"Queue is underflow"; return -1; } int item=items[front]; front++; return item; }
  • 12. Queue Implementation using address // Print all elements Funcion void queue:: print_all_elements () { cout<<"the current items of the queue are:"<<endl; for(int i=front;i<=rear;i++) cout<<items[i]<<" "; cout<<endl; }
  • 13. Queue Implementation using address void main() { clrscr(); queue q; q.insert(1); q.insert(2); q.insert(3); q.insert(4); q.print_all_elements(q); int val=q.remove(); val=q.remove(); q.print_all_elements(); q.insert(5); q.insert(6); q.print_all_elements(); getch(); }