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;
- using System.Threading.Tasks;
- namespace DemoQueue1
- {
- class Queue<ELEMENT>
- {
- private ELEMENT[] data;
- private int head;
- private int tail;
- private int count;
- public Queue(int capacity = 50)
- {
- this.data = new ELEMENT[capacity];
- this.head = this.tail = 0;
- this.count = 0;
- }
- public int Count {
- get { return this.count; }
- }
- private int Next(int position)
- {
- return (++position >= this.data.Length)? 0 : position;
- }
- public void Enqueue(ELEMENT element)
- {
- if (this.count >= this.data.Length)
- {
- throw new Exception("Error la Cola está llena ...");
- }
- this.data[this.tail] = element;
- this.tail = this.Next(this.tail);
- ++this.count;
- }
- public ELEMENT Dequeue()
- {
- if (this.count <= 0)
- {
- throw new Exception("Error la Cola esta vacía ...");
- }
- ELEMENT temp = this.data[this.head];
- this.head = this.Next(this.head);
- --this.count;
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement