{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Data Str &amp; Algorithm HW Solutions 60

# Data Str &amp; Algorithm HW Solutions 60 - if(A[i ==...

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

60 Chap. 9 Searching else { count[i]++; while ((i > 0) && (count[i] > count[i-1])) { swap(A[i], A[i-1]); swap(count[i], count[i-1]); } } } } 9.9 template <class Elem> void MoveToFront(Elem A[]) { // Assume that array is empty to begin with int n = 0; while ((int val = GETNEXT()) != DONE) { for (i=0; i<n; i++) if (A[i] == val) break; if (i == n) A[n] = val; while (i > 0) swap(A[i], A[i-1]); } } 9.10 template <class Elem> void tanspose(Elem A[]) { // Assume that array is empty to begin with int n = 0; while ((int val = GETNEXT()) != DONE) { for (i=0; i<n; i++)
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: if (A[i] == val) break; if (i == n) A[n] = val; if (i != 0) swap(A[i], A[i-1]); } } 9.11 // in1 and in2 are input bit vectors, out is output bit // vector; n is length of bit vector in ints. Assume // the length of the bit vectors are always a number // of ints. void union(int* in1, int* in2, int* out, int n) { for (int i=0; i<n; i++) out[i] = in1[i] | in2[i]; } // in1 and in2 are input bit vectors, out is output bit // vector; n is length of bit vector in ints. Assume...
View Full Document

{[ snackBarMessage ]}