 // Full and almost full binary heaps may be represented (as an implicit data structure) using an array alone.
 struct Heap<T: Comparable> {
     private let items: [T]
-    private let ordering: Ordering
+    private let ordering: Ordering<T>
 }
 
-enum Ordering {
+enum Ordering <T: Comparable> {
     case Min
     case Max
+    
+    func satisfiedInvariantForParent(parent: T, child: T) -> Bool {
+        switch self {
+        case .Min: return parent <= child
+        case .Max: return parent >= child
+        }
+    }
 }
 
 extension Heap {

            return self
        }
        
        switch ordering {
        case .Min :
            if items[parentIndex] > items[index] {
                print(self.description)
                return Heap(items: items.swapValuesForIndices(parentIndex, index), ordering: ordering).upHeap(parentIndex)
            } else {
                return self
            }
        case .Max:
            if items[parentIndex] < items[index] {
                return Heap(items: items.swapValuesForIndices(parentIndex, index), ordering: ordering).upHeap(parentIndex)
            } else {
                return self
            }
        }
    }
    

        case (.None, .None):
            return self
        case (.Some(let left), .None):
            if ordering.satisfiedInvariantForParent(items[index], child: items[left]) {
                return self
            } else {
                return Heap(items: items.swapValuesForIndices(left, index), ordering: ordering).downHeap(left)
            }
        case (.None, .Some(let right)):
            if ordering.satisfiedInvariantForParent(items[index], child: items[right]) {
                return self
            } else {
                return Heap(items: items.swapValuesForIndices(right, index), ordering: ordering).downHeap(right)
            }
        case (.Some(let left), .Some(let right)) where items[left] < items[right]:

