SlideShare una empresa de Scribd logo
1 de 13
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();

}

Más contenido relacionado

La actualidad más candente

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
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 

La actualidad más candente (20)

Function
FunctionFunction
Function
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
The Big Three
The Big ThreeThe Big Three
The Big Three
 
Lecture05
Lecture05Lecture05
Lecture05
 
Faster Python, FOSDEM
Faster Python, FOSDEMFaster Python, FOSDEM
Faster Python, FOSDEM
 
NS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variablesNS2: Binding C++ and OTcl variables
NS2: Binding C++ and OTcl variables
 
Chapter iii(advance function)
Chapter iii(advance function)Chapter iii(advance function)
Chapter iii(advance function)
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Team 6
Team 6Team 6
Team 6
 
Stack operation algorithms with example
Stack operation algorithms with exampleStack operation algorithms with example
Stack operation algorithms with example
 
Array using recursion
Array using recursionArray using recursion
Array using recursion
 
Stack concepts by Divya
Stack concepts by DivyaStack concepts by Divya
Stack concepts by Divya
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Intoduction to dynamic memory allocation
Intoduction to dynamic memory allocationIntoduction to dynamic memory allocation
Intoduction to dynamic memory allocation
 
Heap sort &amp; bubble sort
Heap sort &amp; bubble sortHeap sort &amp; bubble sort
Heap sort &amp; bubble sort
 
Recursion concepts by Divya
Recursion concepts by DivyaRecursion concepts by Divya
Recursion concepts by Divya
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Functors, applicatives, monads
Functors, applicatives, monadsFunctors, applicatives, monads
Functors, applicatives, monads
 
Queue
QueueQueue
Queue
 
Lab 1
Lab 1Lab 1
Lab 1
 

Similar a Queue oop

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
 
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
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
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
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
mustkeem khan
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
Rahul04August
 

Similar a Queue oop (20)

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
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Qprgs
QprgsQprgs
Qprgs
 
week-16x
week-16xweek-16x
week-16x
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Algo>Queues
Algo>QueuesAlgo>Queues
Algo>Queues
 
Data structure , stack , queue
Data structure , stack , queueData structure , stack , queue
Data structure , stack , queue
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
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
 
05 queues
05 queues05 queues
05 queues
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
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
 
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
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
C++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdfC++ Nested loops, matrix and fuctions.pdf
C++ Nested loops, matrix and fuctions.pdf
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++DATA STRUCTURE USING C & C++
DATA STRUCTURE USING C & C++
 
DSU C&C++ Practical File Diploma
DSU C&C++ Practical File DiplomaDSU C&C++ Practical File Diploma
DSU C&C++ Practical File Diploma
 
C++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdfC++ Searching & Sorting5. Sort the following list using the select.pdf
C++ Searching & Sorting5. Sort the following list using the select.pdf
 

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(); }