{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Data Str & Algorithm HW Solutions 60

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

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

View Full Document Right Arrow Icon
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++)
Background image of page 1
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 ]}