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; }
int main(void) { #ifdef TEST_SWAP_INT { int a = 10; int b = -20; swapInt (&a, &b); printf("SwapInt: %d %d\n", a, b); } #endif #ifdef TEST_SWAP_PTR { int a = 10; int b = -20; int *pa = &a; int *pb = &b; swapPtr ((void **)&pa, (void **)&pb); printf("SwapPtr: %d %d\n", *pa, *pb); } #endif return 0; }
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; }
int main() { int a = 10; int b = 15; std::cout<<a<<" "<<b<<"\n"; swapPtr(&a, &b); std::cout<<a<<" "<<b<<"\n"; swapLinks(a, b); std::cout<<a<<" "<<b<<"\n"; return 0; }