void sortByNumber(Element *element, int size) { int i, j; for (i = 0; i < size; i++) // sort from the head to tail for (j = i + 1; j < size; j++) // find the greatest number follows i if (element[i].number > element[j].number) swapElement(element + i, element + j); }
void LogicClass::sortDateAndTime(/*struct textInfo textArray[]*/) { if (sizeOfArray != 0) { for (int i = 0; i < sizeOfArray; i++) { for (int j = i+1; j < sizeOfArray; j++) { if (infoArray[j].startTime < infoArray[i].startTime) { swapElement(infoArray[i], infoArray[j]); } } } //sorts date after time for (int i = 0; i < sizeOfArray; i++) { for (int j = i+1; j < sizeOfArray; j++) { if (infoArray[j].startDate < infoArray[i].startDate) { swapElement(infoArray[i], infoArray[j]); } } } } }
void sort(void* elements, int numberOfElements, int elementSize,Compare compareFunc) { int i, j; void* elementToCompare; void* nextElement; int comparisonResult; for (i = 1; i < numberOfElements; i++) { for (j = 0; j < numberOfElements - i; j++) { elementToCompare = elements + j * elementSize; nextElement = elements + (j + 1) * elementSize; swapElement(elementToCompare ,nextElement ,elementSize ,compareFunc); } } }
void quickSort(ValueOfWord ** tab, int start, int end){ ValueOfWord *pivot; int pivot_index, chg, i; if(end < start) return; pivot_index = (start + end) / 2; pivot = tab[pivot_index]; swapElement(tab, pivot_index, end); for(i = chg = start; i < end; i++){ if(tab[i]->value < pivot->value){ swapElement(tab, i, chg); chg++; } } swapElement(tab, chg, end); quickSort(tab, start, chg - 1); quickSort(tab, chg + 1, end); }
void reverseArrayRecursive(int *arr, int beg, int end) { if (beg > end) return; swapElement(arr, beg, end); reverseArrayRecursive(arr, ++beg, --end); }