diff --git a/SystemExtensions/Collections/CircularQueue.cs b/SystemExtensions/Collections/CircularQueue.cs new file mode 100644 index 0000000..2289a83 --- /dev/null +++ b/SystemExtensions/Collections/CircularQueue.cs @@ -0,0 +1,97 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SystemExtensions.Collections +{ + /// + /// Implementation of a queue based on a circular array. Efficient implementation when capacity is known from before. + /// + /// Provided type. + class CircularQueue : IQueue + { + #region Fields + int count; + int capacity; + int insertLocation; + int readLocation; + T[] items; + #endregion + #region Properties + /// + /// Returns the number of items in the queue. + /// + public int Count { get => count; } + /// + /// Capacity of the queue. + /// + public int Capacity { get => capacity; + set + { + + } + } + #endregion + #region Constructors + public CircularQueue() + { + count = 0; + capacity = 10; + items = new T[capacity]; + } + public CircularQueue(int capacity) + { + this.capacity = capacity; + count = 0; + items = new T[capacity]; + } + #endregion + #region Public Methods + /// + /// Clears the queue. + /// + public void Clear() + { + throw new NotImplementedException(); + } + /// + /// Checks if provided item is present into the queue. + /// + /// Item to be checked. + /// True if item is present. False otherwise. + public bool Contains(T item) + { + throw new NotImplementedException(); + } + /// + /// Removes and returns the first item from the queue. + /// + /// First item from the queue. + public T Dequeue() + { + throw new NotImplementedException(); + } + /// + /// Inserts provided item into the queue. + /// + /// Item to be inserted. + public void Enqueue(T item) + { + throw new NotImplementedException(); + } + /// + /// Checks and returns the first item from the queue without removing it. + /// + /// The first item from the queue. + public T Peek() + { + throw new NotImplementedException(); + } + + #endregion + #region Private Methods + #endregion + } +} diff --git a/SystemExtensions/Collections/IQueue.cs b/SystemExtensions/Collections/IQueue.cs new file mode 100644 index 0000000..bbe5515 --- /dev/null +++ b/SystemExtensions/Collections/IQueue.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SystemExtensions.Collections +{ + /// + /// Interface for queue implementations. + /// + /// Provided type. + public interface IQueue + { + /// + /// Returns the number of items in the queue. + /// + int Count { get; } + /// + /// Inserts item into the queue. + /// + /// Item to be inserted. + void Enqueue(T item); + /// + /// Remove the first item in the queue. + /// + /// First item in the queue. + T Dequeue(); + /// + /// Looks up the first item from the queue without removing it. + /// + /// First item from the queue. + T Peek(); + /// + /// Clears the contents of the queue. + /// + void Clear(); + /// + /// Checks if queue contains an item. + /// + /// Item to be checked. + /// True if queue contains provided item. False otherwise. + bool Contains(T item); + } +} diff --git a/SystemExtensions/Collections/PriorityQueue.cs b/SystemExtensions/Collections/PriorityQueue.cs index b5b49ff..38525ab 100644 --- a/SystemExtensions/Collections/PriorityQueue.cs +++ b/SystemExtensions/Collections/PriorityQueue.cs @@ -11,7 +11,7 @@ namespace SystemExtensions.Collections /// Exposes some of the functionality of the Binary Heap as a queue. /// /// Provided type. - public class PriorityQueue + public class PriorityQueue : IQueue { #region Fields private BinaryHeap binaryHeap; @@ -77,6 +77,15 @@ namespace SystemExtensions.Collections { binaryHeap.Clear(); } + /// + /// Checks if queue contains provided item. + /// + /// Item to be checked. + /// True if queue contains the provided item. False otherwise. + public bool Contains(T item) + { + return binaryHeap.Contains(item); + } #endregion #region Private Methods #endregion diff --git a/SystemExtensions/SystemExtensions.csproj b/SystemExtensions/SystemExtensions.csproj index 409f245..f2c6cca 100644 --- a/SystemExtensions/SystemExtensions.csproj +++ b/SystemExtensions/SystemExtensions.csproj @@ -46,12 +46,15 @@ + + + \ No newline at end of file