Algorithm 5 Insert an Element into a Young Matrix

1:procedure YoungInsert(Y,keyY, key)

2:m=Y.row-numm = Y.\text{row-num}

3:n=Y.col-numn = Y.\text{col-num}

4:if Y[m,n]<Y[m, n] < \infty then

5:error "young matrix overflow"

6:end if

7:YoungDecreaseKey(Y,m,n,keyY, m, n, key)

8:end procedure

9:

10: // decrease Y[i,j]Y[i, j] down to keykey

11:procedure YoungDecreaseKey(Y,i,j,keyY, i, j, key)

12:if key>Y[i,j]key > Y[i, j] then

13:error "new key is larger than the current key"

14:end if

15:Y[i,j]=keyY[i, j] = key

16:while (i>1i > 1 and Y[i1,j]>Y[i,j]Y[i - 1, j] > Y[i, j]) or (j>1j > 1 and Y[i,j1]>Y[i,j]Y[i, j - 1] > Y[i, j]) do

17:if Y[i1,j]>Y[i,j1]Y[i - 1, j] > Y[i, j - 1] then

18:exchange Y[i,j]Y[i, j] with Y[i1,j]Y[i - 1, j]

19:i=i1i = i - 1

20:else

21:exchange Y[i,j]Y[i, j] with Y[i,j1]Y[i, j - 1]

22:j=j1j = j - 1

23:end if

24:end while

25:end procedure