Advertisement
Hazem3529

Untitled

Jan 4th, 2016
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace queue
  7. {
  8.     class ArrayQueue
  9.     {
  10.  
  11.         int[] a;
  12.  
  13.         int rear;
  14.         int front;
  15.  
  16.         public ArrayQueue(int size)
  17.         {
  18.  
  19.             a = new int[size];
  20.  
  21.             rear = front = -1;
  22.        
  23.        
  24.         }
  25.  
  26.  
  27.         public void inqueue(int item)
  28.         {
  29.  
  30.             if (rear == a.Length - 1)
  31.                 Console.WriteLine("queue is full");
  32.  
  33.             else
  34.             {
  35.                 if (front == -1)
  36.                     front = 0; // to put front in first index of array
  37.  
  38.  
  39.                 rear++;
  40.                 a[rear] = item;
  41.             }
  42.            
  43.        
  44.         } //end inqueue
  45.  
  46.  
  47.         public void dequeue()
  48.         {
  49.  
  50.             if (front == -1 || (front>rear))
  51.                 Console.WriteLine("queue is underflow");
  52.  
  53.             else
  54.             {
  55.  
  56.                 Console.WriteLine("the elemernt which delete it : "+a[front]);
  57.  
  58.                 front++;
  59.  
  60.                
  61.            
  62.            
  63.             }
  64.        
  65.         }//end
  66.  
  67.         public void display()
  68.  
  69.         {
  70.            
  71.             for (int i = front; i <= rear; i++)
  72.             {
  73.                 Console.WriteLine("the Queue is :"+a[i]);
  74.             }
  75.        
  76.        
  77.         }
  78.  
  79.  
  80.        
  81.        
  82.        
  83.  
  84.  
  85.  
  86.  
  87.  
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement