Implemented queue interface for standardization.

This commit is contained in:
JavaOopAlgoStudent
2019-05-23 19:53:26 +02:00
parent 8bd96fa35f
commit d9cd4ad5ea
4 changed files with 155 additions and 1 deletions
@@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemExtensions.Collections
{
/// <summary>
/// Implementation of a queue based on a circular array. Efficient implementation when capacity is known from before.
/// </summary>
/// <typeparam name="T">Provided type.</typeparam>
class CircularQueue<T> : IQueue<T>
{
#region Fields
int count;
int capacity;
int insertLocation;
int readLocation;
T[] items;
#endregion
#region Properties
/// <summary>
/// Returns the number of items in the queue.
/// </summary>
public int Count { get => count; }
/// <summary>
/// Capacity of the queue.
/// </summary>
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
/// <summary>
/// Clears the queue.
/// </summary>
public void Clear()
{
throw new NotImplementedException();
}
/// <summary>
/// Checks if provided item is present into the queue.
/// </summary>
/// <param name="item">Item to be checked.</param>
/// <returns>True if item is present. False otherwise.</returns>
public bool Contains(T item)
{
throw new NotImplementedException();
}
/// <summary>
/// Removes and returns the first item from the queue.
/// </summary>
/// <returns>First item from the queue.</returns>
public T Dequeue()
{
throw new NotImplementedException();
}
/// <summary>
/// Inserts provided item into the queue.
/// </summary>
/// <param name="item">Item to be inserted.</param>
public void Enqueue(T item)
{
throw new NotImplementedException();
}
/// <summary>
/// Checks and returns the first item from the queue without removing it.
/// </summary>
/// <returns>The first item from the queue.</returns>
public T Peek()
{
throw new NotImplementedException();
}
#endregion
#region Private Methods
#endregion
}
}
+45
View File
@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SystemExtensions.Collections
{
/// <summary>
/// Interface for queue implementations.
/// </summary>
/// <typeparam name="T">Provided type.</typeparam>
public interface IQueue<T>
{
/// <summary>
/// Returns the number of items in the queue.
/// </summary>
int Count { get; }
/// <summary>
/// Inserts item into the queue.
/// </summary>
/// <param name="item">Item to be inserted.</param>
void Enqueue(T item);
/// <summary>
/// Remove the first item in the queue.
/// </summary>
/// <returns>First item in the queue.</returns>
T Dequeue();
/// <summary>
/// Looks up the first item from the queue without removing it.
/// </summary>
/// <returns>First item from the queue.</returns>
T Peek();
/// <summary>
/// Clears the contents of the queue.
/// </summary>
void Clear();
/// <summary>
/// Checks if queue contains an item.
/// </summary>
/// <param name="item">Item to be checked.</param>
/// <returns>True if queue contains provided item. False otherwise.</returns>
bool Contains(T item);
}
}
+10 -1
View File
@@ -11,7 +11,7 @@ namespace SystemExtensions.Collections
/// Exposes some of the functionality of the Binary Heap as a queue.
/// </summary>
/// <typeparam name="T">Provided type.</typeparam>
public class PriorityQueue<T>
public class PriorityQueue<T> : IQueue<T>
{
#region Fields
private BinaryHeap<T> binaryHeap;
@@ -77,6 +77,15 @@ namespace SystemExtensions.Collections
{
binaryHeap.Clear();
}
/// <summary>
/// Checks if queue contains provided item.
/// </summary>
/// <param name="item">Item to be checked.</param>
/// <returns>True if queue contains the provided item. False otherwise.</returns>
public bool Contains(T item)
{
return binaryHeap.Contains(item);
}
#endregion
#region Private Methods
#endregion
+3
View File
@@ -46,12 +46,15 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Collections\BinaryHeap.cs" />
<Compile Include="Collections\CircularQueue.cs" />
<Compile Include="Collections\FibonacciHeap.cs" />
<Compile Include="Collections\IQueue.cs" />
<Compile Include="Collections\PriorityQueue.cs" />
<Compile Include="Collections\Treap.cs" />
<Compile Include="Comparators.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Threading\PriorityThreadPool.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>