int sortText(Text_t *text, int key, int *StringCount, size_t Textlen) { assert(text); if (!text) Nerror = MEMERR; ErrPrint(Nerror); if (key == 1) { int jump = *StringCount; bool swapped = true; while (jump > 1 || swapped) { if (jump > 1) jump /= 1.24733; swapped = false; for (int i = 0; i + jump < *StringCount; ++i) { assert(&text[i] && &text[i + jump]); if (!(&text[i]) && !(&text[i + jump])) Nerror = STRERR; if (mlStrcmp((&text[i + jump])->StringPos, (&text[i])->StringPos) == -1) { if (!(&text[i]) && !(&text[i + jump])) Nerror = STRERR; assert(&text[i] && &text[i + jump]); swapPtr(&text[i], &text[i + jump]); swapped = true; } ErrPrint(Nerror); } } } else if (key == 2) { int jump = *StringCount; bool swapped = true; while (jump > 1 || swapped) { if (jump > 1) jump /= 1.24733; swapped = false; for (int i = 0; i + jump < *StringCount; ++i) { if (!(&text[i]) && !(&text[i + jump])) Nerror = STRERR; if (mlStrcmpEnd(text[i + jump], text[i]) == -1) { assert(&text[i] && &text[i + jump]); if (!(&text[i]) && !(&text[i + jump])) Nerror = STRERR; swapPtr(&text[i], &text[i + jump]); swapped = true; } ErrPrint(Nerror); } } } findEnd(text, StringCount, Textlen, key); return 1; }
void simplesort(char** text, int len) { char* temp; for (int i = 0; i < len - 1; i++) for (int j = 0; j < len - i - 1; j++) if (mlStrcmp(text[j], text[j + 1]) > 0) { temp = text[j]; text[j] = text[j + 1]; text[j + 1] = temp; } }
int sortText(char** text, int key, int *StringCount, size_t Textlen) { assert(text); if (key == 1) { int jump = *StringCount; bool swapped = true; while (jump > 1 || swapped) { if (jump > 1) jump /= 1.24733; swapped = false; for (int i = 0; i + jump < *StringCount; ++i) { assert(&text[i] && &text[i + jump]); if (mlStrcmp(text[i + jump], text[i]) == -1) { swapPtr(&text[i], &text[i + jump]); swapped = true; } } } } else if (key == 2) { int jump = *StringCount; bool swapped = true; while (jump > 1 || swapped) { if (jump > 1) jump /= 1.24733; swapped = false; for (int i = 0; i + jump < *StringCount; ++i) if (mlStrcmpEnd(text[i + jump], text[i]) == -1) { assert(&text[i] && &text[i + jump]); swapPtr(&text[i], &text[i + jump]); swapped = true; } } } findEnd(text, StringCount, Textlen, key); return Ok; }