 }
 
 extension PriorityQueue: Equatable {
-    public static func ==(lhs: PriorityQueue<T>, rhs: PriorityQueue<T>) -> Bool {
+    public static func ==(lhs: PriorityQueue<Element>, rhs: PriorityQueue<Element>) -> Bool {
         return Array(lhs) == Array(rhs)
     }
 }
 
 extension PriorityQueue: Sequence {
-    public struct PriorityQueueIterator<T: Comparable>: IteratorProtocol {
-        public typealias Element = T
+    public struct Iterator: IteratorProtocol {
 
-        private var queue: PriorityQueue<T>
-        fileprivate init(queue: PriorityQueue<T>) {
+        private var queue: PriorityQueue<Element>
+        fileprivate init(queue: PriorityQueue<Element>) {
             self.queue = queue
         }
 
-        public mutating func next() -> T? {
+        public mutating func next() -> Element? {
             return self.queue.pop()
         }
     }
 
-    public typealias Element = T
-    public typealias Iterator = PriorityQueueIterator<T>
-
-    public func makeIterator() -> PriorityQueueIterator<Element> {
-        return PriorityQueueIterator(queue: self)
+    public func makeIterator() -> Iterator {
+        return Iterator(queue: self)
     }
 }
 

        return "PriorityQueue(count: \(self.underestimatedCount)): \(Array(self))"
    }
}

//
//===----------------------------------------------------------------------===//

public struct PriorityQueue<Element: Comparable> {
    private var heap: Heap<Element>

    public init(ascending: Bool = false) {
        self.heap = Heap(type: ascending ? .minHeap : .maxHeap)
    }

    public mutating func remove(_ key: Element) {
        assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
        _ = self.heap.remove(value: key)
        assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
    }

    public mutating func push(_ key: Element) {
        assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
        self.heap.append(key)
        assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
    }

    public func peek() -> Element? {
        assert(self.heap.checkHeapProperty(), "broken heap: \(self.heap.debugDescription)")
        return self.heap.storage.first
    }
