Contents

adi-sharma26/AdvancedSwiftDataStructures

Contains advanced custom data structures which are not in-built available in swift.

Table of Contents

  1. BinaryHeap
  2. PriorityQueue

[BinaryHeap](#binaryheap)

BinaryHeap is a versatile heap implementation that allows you to choose between a Min Heap or a Max Heap. It provides efficient operations for adding elements and extracting the minimum or maximum value.

Usage

To use a Min Heap:


let minHeap = BinaryHeap<Int>()
minHeap.insert(5)
minHeap.insert(3)
minHeap.insert(8)
// Perform operations on minHeap

To use a Max Heap:


let maxHeap = BinaryHeap<Int>(heapType: .max)
maxHeap.insert(5)
maxHeap.insert(3)
maxHeap.insert(8)
// Perform operations on maxHeap

[PriorityQueue](#priorityqueue)

PriorityQueue is a data structure that allows you to enqueue elements with associated priorities. Elements are dequeued based on their priority, providing a flexible and efficient way to manage tasks or items with different levels of importance.

Usage


var priorityQueue = PriorityQueue<String, Int>()
priorityQueue.enqueue("Task A", withPriority: 3)
priorityQueue.enqueue("Task B", withPriority: 1)
priorityQueue.enqueue("Task C", withPriority: 2)
// Dequeue items based on priority
let highestPriorityTask = priorityQueue.dequeue()

Contribution

Contributions are welcome! If you have ideas for improvements, additional features, or new data structures, feel free to open an issue or submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Package Metadata

Repository: adi-sharma26/AdvancedSwiftDataStructures

Stars: 1

Forks: 0

Open issues: 0

Default branch: main

Primary language: swift

License: MIT

README: README.md