int main(int argc, char* argv[]) { std::vector<int> foo; foo.push_back(5); foo.push_back(8); foo.push_back(1); foo.push_back(2); foo.push_back(4); foo.push_back(7); foo.push_back(6); foo.push_back(3); for (int i = 0; i < foo.size(); i++) std::cout << foo[i] << " "; std::cout << std::endl; selectionSort(foo); for (int i = 0; i < foo.size(); i++) std::cout << foo[i] << " "; std::cout << std::endl << std::endl; std::vector<double> bar; bar.push_back(5.5); bar.push_back(8.8); bar.push_back(1.1); bar.push_back(2.2); bar.push_back(4.4); bar.push_back(7.7); bar.push_back(6.6); bar.push_back(3.3); for (int i = 0; i < bar.size(); i++) std::cout << bar[i] << " "; std::cout << std::endl; selectionSort(bar); for (int i = 0; i < bar.size(); i++) std::cout << bar[i] << " "; std::cout << std::endl << std::endl; std::vector<BankAccount> men(8); men[0].setBalance(420); men[0].setInterest(0.1); men[1].setBalance(300); men[1].setInterest(0.08); men[2].setBalance(1920); men[2].setInterest(0.16); men[3].setBalance(666); men[3].setInterest(0.18); men[4].setBalance(1080); men[4].setInterest(0.03); men[5].setBalance(0); men[5].setInterest(1.2); men[6].setBalance(2390); men[6].setInterest(0.75); men[7].setBalance(515); men[7].setInterest(1); for (int i = 0; i < men.size(); i++) std::cout << men[i].getBalance() << " "; std::cout << std::endl; selectionSort(men); for (int i = 0; i < men.size(); i++) std::cout << men[i].getBalance() << " "; std::cout << std::endl; return 0; }
int main(){ printf("******MENU******\n\nMetodo de entrada da ARRAY:\n1- Ja Ordenado\n2- Aleatorio\n3- Ordem Inversa\n4- Exit\n\nOpcao: "); scanf("%d", &opc); while(opc != 4) { switch(opc) { case 1:{ printf("\nVETOR DADO\n"); for(i=0; i<N; i++){ A[i] = i; printf("%d \n", A[i]); } selectionSort(); printf("\nVETOR ORDENADO\n"); for(i=0; i<N; i++){ printf("%d \n", A[i]); } break; } case 2:{ printf("\nVETOR DADO\n"); for(i=0; i<N; i++){ A[i] = rand() % 100; printf("%d \n", A[i]); } selectionSort(); printf("\nVETOR ORDENADO\n"); for(i=0; i<N; i++){ printf("%d \n", A[i]); } break; } case 3:{ x = N; printf("\nVETOR DADO\n"); for(i=0; i<N; i++){ A[i] = x; x--; printf("%d \n", A[i]); } selectionSort(); printf("\nVETOR ORDENADO\n"); for(i=0; i<N; i++) { printf("%d \n", A[i]); } break; } } } getch(); }
int QCArrayClass::CheckTensor(int nindex1, int indexarray1[], int nindex2, int indexarray2[], int nindex3, int indexarray3[], int &nindexr, int indexarrayr[]) const { int i, i2, i3; nindexr=0; int sortindexarray1[mx_array_dim], sortindexarray2[mx_array_dim], sortindexarray3[mx_array_dim]; int contractionarray[2*mx_array_dim], contractnindex; selectionSort(indexarray1, sortindexarray1, nindex1); selectionSort(indexarray2, sortindexarray2, nindex2); selectionSort(indexarray3, sortindexarray3, nindex3); /*check tensor index of array*/ /*merge two arrays*/ i2=i3=0; contractnindex=0; while (i2<nindex2 && i3<nindex3) { if (sortindexarray2[i2]>sortindexarray3[i3]) contractionarray[contractnindex++]=sortindexarray3[i3++]; else if (sortindexarray2[i2]<sortindexarray3[i3]) contractionarray[contractnindex++]=sortindexarray2[i2++]; else /*==*/ { indexarrayr[nindexr++]=sortindexarray2[i2]; i2++; i3++; } } while (i2<nindex2) contractionarray[contractnindex++]=sortindexarray2[i2++]; while (i3<nindex3) contractionarray[contractnindex++]=sortindexarray3[i3++]; /*compare array1 and calculated contraction array*/ if (nindex1!=contractnindex) { outerror(glno, "error in tensor index."); return -2; } for (i=0; i<nindex1; i++) { if (contractionarray[i]!=sortindexarray1[i]) { outerror(glno, "tensor array doesn't match."); return -1; } } return 0; }
int main() { srand(time(NULL)); int num[max], t, i; time_t tI, tF; tI = time(NULL); for(i=0; i<max; i++) num[i] = rand()%100; for(i=0; i<max; i++) printf("%d\t", num[i]); printf("\n\n"); selectionSort(num, max); for(i=0; i<max; i++) printf("%d\t", num[i]); tF = time(NULL); t = difftime(tF, tI); printf("\n\n%d seg", t); return 0; }
void main() { char op = 's', l; int x, tam; char *letras; do { letras = digiteLetra(); tam = strlen(letras); printf("Digite a opção desejada:\n1. Insertion Sort\n2. Selection sort\n3. Bubble sort\n4. Comb sort\n5. Merge sort\nSua escolha: "); scanf("%d", &x); switch(x) { case 1: insertionSort(letras, tam); break; case 2: selectionSort(letras, tam); break; case 3: bubbleSort(letras,tam); break; case 4: combSort(letras, tam); break; case 5: fazMergeSort(letras, tam); break; }; printf("Deseja continuar? [s/n]: "); scanf("%s", &op); } while (op == 's'); system("pause"); }
void Sorts<T>::setMedianPivot(T arr[], int first, int last) { T tempval; int mid = (last+first)/2; T temp [] = {arr[first], arr[mid], arr[last]}; selectionSort(temp, 3); if(temp[1]==arr[first]) { tempval = arr[last]; arr[last] = arr[first]; //first at the end arr[first] = tempval; } else if (temp[1]==arr[mid]) { tempval = arr[last]; arr[last] = arr[mid]; //middle at the end arr[last] = tempval; } }
/* * This program takes a list of integers as command line arguments * and sort them by calling the function selectionSort. */ int main (int argc, char** argv) { if (argc < 2) { fprintf(stderr, "Usage: ./selection-sort n1 n2 ...\n"); return EXIT_FAILURE; } // Declare the array int elements[argc - 1]; // Populate the array for (int i = 1; i < argc; ++i) { elements[i - 1] = atoi(argv[i]); printf("%d ", elements[i - 1]); } printf("\b\n"); // Sort the array selectionSort(elements, argc - 1); // Print out the sorted array for (int i = 0; i < argc - 1; ++i) { printf("%d ", elements[i]); } printf("\b\n"); return EXIT_SUCCESS; }
/* main execution of program */ int main (){ int last = 0; /* index tracking */ int list[SIZE] = {}; /* initialize array to 0's regardless of default fill values */ fillArray(list, TRUE); /* set up random function feed, set up only once per program */ srand (time(NULL)); /* fill array with random numbers */ fillArray(list, FALSE); /* print list before is sorted */ printf("list of values before sorting\n"); printArray(list); if (isAscending(list, SIZE)) { /* do nothing, if you want ascending array */ }else if(isDescending(list, SIZE)) { /* if it is descending order, reverse the array */ reverse(list, 0, SIZE - 1); } else { /* sort list in ascending order */ last = SIZE - 1; selectionSort(list, last); } /* print list after is sorted */ printf("list of values after sorting\n"); printArray(list); return 0; } /* end main */
int main(){ int arr[8] = {2,56,2,35,6,4,2,87}; printArray(arr, sizeof arr / sizeof *arr); printf("\n"); selectionSort(arr, sizeof arr / sizeof *arr); printArray(arr, sizeof arr / sizeof *arr); }
int main() { // Testing Selection Sort std::cout << "Here's an unsorted array!" << std::endl; int arr[] = {2,7,4,1,5,3}; for (int i = 0; i < 6; i++) { std::cout << arr[i] << " "; } std::cout << "\nRunning selection sort..." << std::endl; selectionSort(arr, 6); for (int i = 0; i < 6; i++) { std::cout << arr[i] << " "; } std::cout << "\n"; // Testing Insertion Sort std::cout << "Here's another unsorted array!" << std::endl; int arr2[] = {6,3,1,0,8,8}; for (int i = 0; i < 6; i++) { std::cout << arr2[i] << " "; } std::cout << "\nRunning insertion sort..." << std::endl; insertionSort(arr2, 6); for (int i = 0; i < 6; i++) { std::cout << arr2[i] << " "; } std::cout << "\n"; return 0; }
void partition(int arr[],int low,int high,int n) { int mid,status; if(high-low<=4) selectionSort(arr,low,high,n); else { mid=(low+high)/2; pid_t pid1,pid2; if((pid1=fork())<0) { perror("fork Failed"); exit(1); } if (pid1==0) { partition(arr,low,mid,n); exit(0); } waitpid(pid1, &status, 0); if((pid2=fork())<0) { perror("fork Failed"); exit(1); } if(pid2==0) { partition(arr,mid+1,high,n); exit(0); } waitpid(pid2, &status, 0); mergeSort(arr,low,mid,high,n); } }
int main() { int numOfNum = 0; printf("Enter the number of numbers you want to sort.\n"); scanf("%d", &numOfNum); if (numOfNum <= 0) { printf("Invalid input. Exiting!\n"); return 0; } int theNumbers[numOfNum]; printf("Now, enter the numbers to be sorted in a single line separated by spaces.\n"); for (int i = 0; i < numOfNum; i++) // Take input of the numbers scanf("%d", &theNumbers[i]); selectionSort(theNumbers, numOfNum); /* Output the numbers in sorted order */ for (int i = 0; i < numOfNum; i++) { printf("%d ", theNumbers[i]); } printf("\n"); return 0; }
int main(int argc, const char *argv[]) { int n[LIMIT]; std::random_device rd; std::mt19937 gen(rd()); std::uniform_int_distribution<int> dis(1, 100); for (int i = 0; i < LIMIT; ++i) { n[i] = dis(gen); } // print unsorted array std::cout << "Before selectionSort: " << std::endl; for (int i = 0; i < LIMIT; ++i) { std::cout << n[i] << std::endl; } selectionSort(n, LIMIT); // print sorted array std::cout << "\nAfter selectionSort: " << std::endl; for (int i = 0; i < LIMIT; ++i) { std::cout << n[i] << std::endl; } return 0; }
int main(){ int a[10] = {65, 75, 90, 12 , 27}; int i,j; printArray(a, 5); selectionSort(a, 5); return 1; }
int main (void){ //경우1 테스트 clock_t start, end; double duration1=0; int list1[] ={15, 11, 9, 8, 7, 5, 3, 2}; int size = ((int)sizeof(list1)/sizeof(int)); printArr(list1, size); start= clock(); selectionSort(list1, size); end= clock(); printArr(list1, size); duration1 = ((double)end-start)/CLOCKS_PER_SEC; printf("time : %f \n\n", duration1); int i, n, step = 100; int a[MAX_SIZE]; double duration; FILE* time = fopen("time.xls", "wb"); if (time == NULL){ puts("Write Error"); return 0; } char temp[100]; for(n=0; n<=MAX_SIZE; n+=step){ for(i=0;i<n;i++) a[i] = n - i; start = clock(); selectionSort(a, n); end = clock(); duration = ((double) (end - start))/CLOCKS_PER_SEC; sprintf(temp,"time %d : %f\n", n, duration); fputs(temp, time); } fclose(time); return 0; }
int find(int * a,int k,int size) { if(k<=size/2) return selectionSort(a,k-1,size); else return bubbleSort(a,k-1,size); return 0; }
int main(void) { int array[7] = { 22, 11, 99, 88, 9, 7, 42 }; std::cout << "Before Sort: " << std::endl; printArr(array); selectionSort(array); std::cout << "After Sort: " << std::endl; printArr(array); }
int main(void){ int array[25]={5,6,7,1,2,3,-10,56,100,-1}; int location; int key=-20; location = linearSearch(key,array,10); printf("the number %d was found at : %d\n",key,location); selectionSort(array,10); printArray(array,10,10); }
int main() { //int arr[10] = { 10,9,8,7,6,5,4,3,2,1 }; int arr[6] = { 3,7,2,5,1,4, }; int arrSize = sizeof(arr) / sizeof(arr[0]); selectionSort(arr, arrSize); }
main() { printf("Input Array: "); display(); printline(50); selectionSort(); printf("Output Array: "); display(); printline(50); }
int main(){ int numList[] = {4, 2, 5, 3, 1}; selectionSort(numList, 5); printList(numList); return 0; }
void main(void) { int values[4] = {7, 2, 8, 1}; cout << "The unsorted values are\n"; showArray(values, 4); selectionSort(values, 4); cout << "The sorted values are\n"; showArray(values, 4); }
int main(int argc, char *argv[]) { int i; int test[10] = {1, 3, 2, 9, 10, 8, 4, 5, 7, 6}; selectionSort(test, 10); for(i = 0; i < 10; ++i) printf("%d ", test[i]); printf("\n"); return 0; }
int main(){ int aSize = 0; cnt = 0; cout<<"Enter array size: ";cin>>aSize; int *strArray = new int[aSize]; int *orgArray = new int[aSize]; int search = aSize; //getArray(strArray,aSize); fillRand(strArray,aSize); printAr(strArray,aSize); copyArray(strArray,orgArray,aSize); cout<<"******** standard search **********"<<endl; cout<<"Found "<<search<<" at "; cout<<standardSearch(strArray,aSize, search); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; cout<<"******** binary search **********"<<endl; cout<<"Found "<<search<<" at "; selectionSort(strArray,aSize); cout<<binarySearch(strArray,aSize,search); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; copyArray(orgArray,strArray,aSize); cout<<"******** selection sort **********"<<endl; selectionSort(strArray,aSize); printAr(strArray,aSize); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; copyArray(orgArray,strArray,aSize); cout<<"******** insert sort **********"<<endl; insertSort(strArray,aSize); printAr(strArray,aSize); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; copyArray(orgArray,strArray,aSize); cout<<"******** Bubble sort **********"<<endl; BubbleSort(strArray,aSize); printAr(strArray,aSize); cout<<" comparisons: "<<cnt<<endl<<"***********************"<<endl<<endl; return 0; }
int main(void) { int i; int test[6]={5,2,4,52,12,42}; selectionSort(test,6); for(i=0;i<6;i++) { printf("%d ",test[i]); } }
// Driver program to test above functions void main() { int n = sizeof(arr)/sizeof(arr[0]); Echo("n:"); Echo(itoa(n)); Echo("Begin:");Echo(itoa(GetTick())); selectionSort(arr, n); Echo("End:");Echo(itoa(GetTick())); Echo("Sorted array"); printArray(arr, n); exit(); }
int testaSelection(int tam){ int v[tam], n=tam; clock_t t; geraVetor(v,n); t = clock(); selectionSort(v,n); t = clock() - t; return t; }
int main(void) { int A[] = {2,7,4,1,5,3}; int arr_length = sizeof(A)/ sizeof(A[0]); printf("Before sorting : "); printArray(A,arr_length); selectionSort(A, arr_length); printf("After sorting : "); printArray(A, arr_length); return 0; }
int main(void) { int n,i; int arr[100]; scanf("%d",&n); for(i=0;i<=n-1;i++) scanf("%d",&arr[i]); selectionSort(arr,n); for(i=0;i<=n-1;i++) printf("%d\n",arr[i]); return 0; }
int main(){ srand(time(NULL)); int A[n]; feelArray(A, n); printf("Array A before sorting:\n"); printArray(A, n); selectionSort(A, n); printf("\n"); printf("Array A after sorting:\n"); printArray(A, n); return 0; }