Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace queue
- {
- class ArrayQueue
- {
- int[] a;
- int rear;
- int front;
- public ArrayQueue(int size)
- {
- a = new int[size];
- rear = front = -1;
- }
- public void inqueue(int item)
- {
- if (rear == a.Length - 1)
- Console.WriteLine("queue is full");
- else
- {
- if (front == -1)
- front = 0; // to put front in first index of array
- rear++;
- a[rear] = item;
- }
- } //end inqueue
- public void dequeue()
- {
- if (front == -1 || (front>rear))
- Console.WriteLine("queue is underflow");
- else
- {
- Console.WriteLine("the elemernt which delete it : "+a[front]);
- front++;
- }
- }//end
- public void display()
- {
- for (int i = front; i <= rear; i++)
- {
- Console.WriteLine("the Queue is :"+a[i]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement