Last active
August 29, 2015 14:05
-
-
Save anvarazizov/a3c8b19194f935810f16 to your computer and use it in GitHub Desktop.
Поки що не фіналізований метод.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)sortArray:(NSMutableArray *)array withLeft:(NSInteger )left andRight:(NSInteger )right | |
{ | |
NSInteger i = left - 1; | |
NSInteger j = right; | |
NSInteger p = left - 1; | |
NSInteger q = right; | |
if (right <= left) | |
return; | |
id v = array[right]; | |
for (; ; ) | |
{ | |
while ([array[++i] compare:v] == NSOrderedAscending); | |
while ([v compare:array[--j]] == NSOrderedAscending) | |
if (j == left) break; | |
if (i >= j) break; | |
[array exchangeObjectAtIndex:i withObjectAtIndex:j]; | |
if ([array[i] compare:v] == NSOrderedSame) | |
{ | |
p++; | |
[array exchangeObjectAtIndex:p withObjectAtIndex:i]; | |
} | |
if ([v compare:array[j]] == NSOrderedSame) | |
{ | |
q--; | |
[array exchangeObjectAtIndex:j withObjectAtIndex:q]; | |
} | |
} | |
[array exchangeObjectAtIndex:i withObjectAtIndex:right]; | |
j = i - 1; | |
i = i + 1; | |
for (int k = left; k < p; k++) | |
{ | |
[array exchangeObjectAtIndex:k withObjectAtIndex:j--]; | |
} | |
for (int k = right - 1; k > q; k--, i++) | |
{ | |
[array exchangeObjectAtIndex:i withObjectAtIndex:k]; | |
} | |
[self sortArray:array withLeft:left andRight:j]; | |
[self sortArray:array withLeft:i andRight:right]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment