Algorithm 1 Mergable Heap Implemented with Sorted List

1:procedure MakeHeap()

2:Let LL be an empty singly linked list, i.e. L.headL.head is NILNIL

3:return LL

4:end procedure

5:

6:procedure Insert(L,xL, x)

7:if L.head==NILL.head == NIL or x.keyL.head.keyx.key \le L.head.key then

8:x.next=L.headx.next = L.head

9:L.head=xL.head = x

10:else

11:prev=L.headprev = L.head

12:cur=L.head.nextcur = L.head.next

13:while curNILcur \ne NIL and x.key>cur.keyx.key > cur.key do

14:prev=curprev = cur

15:cur=cur.nextcur = cur.next

16:end while

17:prev.next=xprev.next = x

18:x.next=curx.next = cur

19:end if

20:end procedure

21:

22:procedure Minimum(LL)

23:return L.headL.head

24:end procedure

25:

26:procedure ExtractMin(LL)

27:if L.head==NILL.head == NIL then

28:return NILNIL

29:end if

30:x=L.headx = L.head

31:L.head=x.nextL.head = x.next

32:return xx

33:end procedure

34:

35:procedure Union(L1,L2L_1, L_2)

36:if L1.head==NILL_1.head == NIL then

37:return L2L_2

38:else if L2.head==NILL_2.head == NIL then

39:return L1L_1

40:else

41:p1=L1.headp_1 = L_1.head

42:p2=L2.headp_2 = L_2.head

43:Let LL be an empty singly linked list, i.e. L.headL.head is NILNIL.

44:if p1.key<p2.keyp_1.key < p_2.key then

45:L.head=p1L.head = p_1

46:p1=p1.nextp_1 = p_1.next

47:else

48:L.head=p2L.head = p_2

49:p2=p2.nextp_2 = p_2.next

50:end if

51:tail=L.headtail = L.head

52:while p1NILp_1 \ne NIL and p2NILp_2 \ne NIL do

53:if p1.key<p2.keyp_1.key < p_2.key then

54:tail.next=p1tail.next = p_1

55:tail=p1tail = p_1

56:p1=p1.nextp_1 = p_1.next

57:else

58:tail.next=p2tail.next = p_2

59:tail=p2tail = p_2

60:p2=p2.nextp_2 = p_2.next

61:end if

62:end while

63:if p1NILp_1 \ne NIL then

64:tail.next=p1tail.next = p_1

65:else if p2NILp_2 \ne NIL then

66:tail.next=p2tail.next = p_2

67:end if

68:return LL

69:end if

70:end procedure