{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

localvars2

# localvars2 - .k-1<= b[k.n for int k= 0 k< n k= k 1 Set...

This preview shows page 1. Sign up to view the full content.

1 CS101J, Cornel 0 Declare a local variable where it logically belongs /** Sort array segment b[0. .n] */ public void selectionSort( int[] b, int n) { int temp; int j; // inv: b[0. .k-1] <= b[k. .n] for ( int k= 0; k < n; k= k+1) { // Set j to the index of the minimum of b[k. .n] j= k; for ( int p= k+1; p<= n; p= p+1) { if (b[p] < b[j]) j= p; } // Swap b[j] and b[k] temp= b[j]; b[j]= b[k]; b[k]= temp; } } inv : b sorted <= >= 0 k n Generally, close to its ﬁrst use CS101J, Cornel 1 Declare local variables where they logically belong /** Sort array segment b[0. .n] */ public void selectionSort( int[] b, int n) { int j; // inv: b[0.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: .k-1] <= b[k. .n] for ( int k= 0; k < n; k= k+1) { // Set j to the index of the minimum of b[k. .n] j= k; for ( int p= k+1; p<= n; p= p+1) { if (b[p] < b[j]) j= p; } // Swap b[j] and b[k] int temp= b[j]; b[j]= b[k]; b[k]= temp; } } inv : b sorted <= >= 0 k n CS101J, Cornel 2 Declare local variables where they logically belong /** Sort array segment b[0. .n] */ public void selectionSort( int b, int n) { // inv: b[0. .k-1 is sorted & b[0. .k-1] <= b[k. .n] for ( int k= 0; k < n; k= k+1) { // Set j to the index of the minimum of b[k. .n] int j= k; for ( int p= k+1; p<= n; p= p+1) { if (b[p] < b[j]) j= p; } // Swap b[j] and b[k] int temp= b[j]; b[j]= b[k]; b[k]= temp; } } inv : b sorted <= >= 0 k n...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online