Professional Documents
Culture Documents
Cs 201 Assgnment Solution
Cs 201 Assgnment Solution
Cs 201 Assgnment Solution
#include <iostream>
#include <string>
#include <cstring>
#include <cctype>
c << "For arrays A1 and A2, enter up to " << N << endl;
c << "characters (not counting spaces)" << endl;
c << "A1 > ";
getline(cin,line);
for (i = line.begin(), j = 0; (i != line.end()) && (j < N); i++) {
if (*i != space) a1[j++] = *i;
}
c << "A2 > ";
getline(cin,line);
for (i = line.begin(), j = 0; (i != line.end()) && (j < N); i++) {
if (*i != space) a2[j++] = *i;
}
// Merge
for (j = 0, k = 0; j < N; j++) {
merged[k++] = a1[j];
if (strchr(a1,a2[j]) == NULL) {
merged[k++] = a2[j];
}
}
c << "Merged : ";
printArray(merged);
// Sort
selectionSort(merged,k);
delete [] a1;
delete [] a2;
delete [] merged;
return 0;
}
c << endl;
}
//
// Selection sort of a char array, ignoring case.
//
void selectionSort(char *a, size_t n) {
char min, t;
#if 0
Sample run:
#endif