Heap data structure implementation in swift
class MaxHeap<T: Comparable> { var heap: = func insert(_ element: T) { heap.append(element) var currentIndex = heap.count - 1 while currentIndex > 0 && heap > heap { heap.swapAt(currentIndex, (currentIndex-1)/2) currentIndex = (currentIndex-1)/2 } } func remove() -> T? { guard !heap.isEmpty else { return nil } let topElement = heap…