public static LeftistHeap heapify(int[] A) { Queue <Node> queue = new Queue <Node>(); for (int i = 0; i < A.Length; i++) { queue.Enqueue(new Node(A[i])); } int size = queue.Count; while (queue.Count > 1) { for (int i = 0; i < size; i++) { if (queue.Count == 1) { return(new LeftistHeap(queue.Dequeue())); } Node n1 = queue.Dequeue(); Node n2 = queue.Dequeue(); queue.Enqueue(LeftistHeap.merge(n1, n2)); } } return(new LeftistHeap(queue.Dequeue())); }
public static int[] sort(ref int[] A) { LeftistHeap heap = heapify(A); for (int i = 0; i < A.Length; i++) { A[i] = heap.extract_min(); } return(A); }
public void merge(LeftistHeap h) { root = merge(root, h.root); h.root = null; }