Skip to main content

Example - insert sort

Task 1

introduction from section 9.1.2 of the Textbook + source code

void insertSort(int a[], int length)

{

int i, j, value;

for (i = 1; i < length; ++i)s

{

value = a[i];

for (j = i - 1; j >= 0 && a[j] > value; --j)

{

a[j + 1] = a[j];

}

a[j + 1] = value;

}

}



instruction

1

for (i = 1/*B1*/; i < length/*B2*/; ++i/*B3*/)

2

value = a[i]/*B4*/;

3

for (j = i - 1/*B5*/; j >= 0 && a[j]> value/*B6*/ ; --j/*B7*/)

4

a[j + 1] = a[j]/*B8*/;

5

a[j + 1] = value/*B9*/;

image.png

image 9.1