Element | Index | Location | Location |
---|---|---|---|
1 | 0 | $b$ | $b+(1-1)e$ |
2 | 2 | $b+e$ | $b+(2-1)e$ |
3 | 3 | $b+2e$ | $b+(3-1)e$ |
n | n | $b+(n-1)e$ | $b+(n-1)e$ |
$1≤ k ≤ n | k | $b+(k-1)e$ | $b+(k-1)e$ |
for (i = 0; i < size; i++) { A[i] = A[i] + 1; }
la $r1, A ; the base addres of the array li $r2, 0 ; the index li $r4, n ; loop termination condition TOP: beq $r2, $r4 OUT multi $r3, $r2, ELEMENT_SIZE; (n-1)*e add $r3, $r1, $r3 b + (n-1) * e; lw $r5, 0($r3) addi $r5, $r5, 1 sw $r5, 0($r3) addi $r2, 1 b TOP OUT:
addi $r3, $r3, ELEMENT_SIZE
for each data d Insert d into array a Sort(a)
Insert(a, e) loc = a.size() while(loc > 0 and a[loc-1] > e) ary[loc] = ary[loc-1] loc -- a[loc] = e
loc
ever be out of bounds?