Tuesday, November 17, 2009

CS201

#include using namespace std; void sort(char array[], int length); int main() { char firstArray[15]; char secondArray[15]; char mergedArray[30]; bool flag = false; int i; int mergedIndex; cout<<"Enter into First Array\n"; fgets(firstArray, sizeof(firstArray), stdin); cout<<"Enter into Second array\n"; fgets(secondArray, sizeof(secondArray), stdin); // Copy the first array into the merged array for(i = 0; firstArray[i] != '\n'; ++i) { mergedArray[i] = firstArray[i]; } mergedIndex = i; //Copy second array into merged array for(i = 0; secondArray[i] != '\n'; ++i) { mergedArray[mergedIndex++] = secondArray[i]; } mergedArray[mergedIndex] = 0; cout<<"\nMerged : "; for(i = 0; i<> { cout< } sort(mergedArray, mergedIndex); cout<<"\nSorted : "; for(i = 0; i<> { cout< } system("PAUSE"); return EXIT_SUCCESS; } void sort(char array[], int length) { int stop = length - 1; for (int i = 0; i <> { for (int j = 0; j <> { if (array[j] > array[j+1]) { char tmp = array[j]; array[j] = array[j+1]; array[j+1] = tmp; } } } }
#include #include #include #include using namespace std; const size_t N = 10; const char space = ' '; void selectionSort(char *, size_t length); void printArray(const char *); int main(int argc, char *argv[]) { string line; string::iterator i; size_t j, k; char *a1 = new char[N], *a2 = new char[N], *merged = new char[N*2]; c << "For arrays A1 and A2, enter up to " <<> "; getline(cin,line); for (i = line.begin(), j = 0; (i != line.end()) && (j <> "; getline(cin,line); for (i = line.begin(), j = 0; (i != line.end()) && (j < j =" 0," k =" 0;" i =" 0;" i =" 0;" min =" i;" j =" i+1;" min =" j;" t =" a[min];"> a h b c u v I j k e A2 > y u d f g k I w q a Merged : a y h b d c f u g v I j w k q e Sorted : a b c d e f g h I j k q u v w y #endif
#include using namespace std; void merge(char[],int, char[],int ,char[],int&); void fill(char[], int&,char[],int,int&); void print(char[],int,string); void input(char[],int,string); void sort(char[],int); bool already(char,char[],int); int main() {char a[10],b[10],c[20]; int asize=10,csize=0,bsize=10; input (a,asize,"array 1"); input (b,bsize,"array 2"); print(a,asize,"Original Array 1"); print(b,bsize,"Original Array 2"); merge(a,asize,b,bsize,c,csize); print(c,csize,"Merged Array"); sort(c,csize); print(c,csize,"Sorted Merged Array"); system("pause"); return 0; } void print(char a[],int n,string mess) {int i; cout< i="0;i" aupto="0,bupto=" turn="0;" turn="=" aupto="=" turn="1;" bupto="=" turn="0;" i="0;i" j="i;j" t="a[i];" i="0;i">>a[i]; } bool already(char a,char c[],int csize) {int i; for(i=0;i if(a==c[i]) return true; return false; }

No comments: