Table of Contents

Class IndexPriorityQueue<T>

Namespace
AlgorithmsSW.PriorityQueue
Assembly
AlgorithmsSW.dll

Represents a generic index-based priority queue where elements are ordered based on their priority determined by an IComparer.

public class IndexPriorityQueue<T>

Type Parameters

T

The type of elements in the priority queue.

Inheritance
IndexPriorityQueue<T>
Inherited Members
Extension Methods

Remarks

This implementation of a priority queue uses an array-based binary heap. It associates each value with an index, allowing for efficient updates of the queue based on index.

Constructors

IndexPriorityQueue(int, IComparer<T>)

Initializes a new instance of the IndexPriorityQueue<T> class with a specified capacity and comparer.

public IndexPriorityQueue(int capacity, IComparer<T> comparer)

Parameters

capacity int

The maximum number of elements the priority queue can hold.

comparer IComparer<T>

The IComparer to determine the priority of elements.

Properties

Count

Gets the number of elements currently in the priority queue.

public int Count { get; }

Property Value

int

IsEmpty

Gets a value indicating whether the priority queue is empty.

public bool IsEmpty { get; }

Property Value

bool

true if the queue is empty; otherwise, false.

Methods

Contains(int)

Determines whether the priority queue contains the specified index.

public bool Contains(int index)

Parameters

index int

The index to check for presence in the queue.

Returns

bool

true if the index is in the queue; otherwise, false.

Insert(int, T)

Inserts a value with an associated index into the priority queue.

public void Insert(int index, T value)

Parameters

index int

The index associated with the value.

value T

The value to insert.

PeekMin()

Returns the minimum element of the priority queue without removing it.

public (int index, T value) PeekMin()

Returns

(int index, T value)

A tuple containing the index and value of the minimum element.

PopMin()

Removes and returns the minimum element from the priority queue.

public (int index, T value) PopMin()

Returns

(int index, T value)

A tuple containing the index and value of the minimum element that was removed.

UpdateValue(int, T)

Updates the value of the element at the specified index.

public void UpdateValue(int index, T newValue)

Parameters

index int

The index of the element to update.

newValue T

The new value to replace the current value.