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 TASK02_QUEUES
- {
- class Program
- {
- static void Main(string[] args)
- {
- char addMore, removeMore, remove;
- int[] Array = new int[10];
- Array[0] = 3;
- Array[1] = 5;
- Array[2] = 4;
- Queues queuearray = new Queues(Array);
- queuearray.Display();
- do
- {
- Console.WriteLine("ENTER VALVE");
- int value = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("ENTER {0}'s Priority in Number", value);
- int Priority = Convert.ToInt32(Console.ReadLine());
- queuearray.EnQueue(value, Priority);
- queuearray.Display();
- Console.WriteLine("DO YOU WANT TO ADD MORE?(Y/N)");
- addMore = Convert.ToChar(Console.ReadLine());
- }
- while (addMore == 'y' || addMore == 'Y');
- Console.Clear();
- Console.WriteLine("DO YOU WANT TO REMOVE A VALUE?(Y/N)");
- remove = Convert.ToChar(Console.ReadLine());
- if (remove == 'y' || remove == 'Y')
- {
- do
- {
- queuearray.Display();
- queuearray.DeQueue();
- queuearray.Display();
- Console.WriteLine("DO YOU WANT TO REMOVE MORE?(Y/N)");
- removeMore = Convert.ToChar(Console.ReadLine());
- } while (removeMore == 'y' || removeMore == 'Y');
- }
- }
- }
- class Queues
- {
- private int[] queueArray;
- private int upBound, queueElelment;
- public Queues(int[] queueArray)
- {
- this.queueArray = queueArray;
- upBound = queueArray.Length;
- }
- public void Display()
- {
- Console.Write("QUEUE: ");
- for (int i = 0; i < queueArray.Length; i++)
- {
- Console.Write("{0} ", queueArray[i]);
- }
- Console.WriteLine();
- }
- public void EnQueue(int value, int Priority)
- {
- Priority = Priority - 1;
- if (queueArray[Priority] > 0)
- {
- Console.WriteLine("Element with same priority already existed.\nPlease Add the element again with different priority.");
- }
- else
- {
- queueArray[Priority] = value;
- }
- }
- public bool DeQueue()
- {
- if (queueElelment < upBound)
- {
- for (int i = 0; i < upBound - 1; i++)
- {
- if (queueArray[i] != 0)
- {
- queueArray[i] = queueArray[i + 1];
- queueElelment = i + 1;
- }
- }
- queueArray[queueElelment] = 0;
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement