Last active
August 29, 2015 14:03
-
-
Save saturngod/935c47cc29bcd1aa90f6 to your computer and use it in GitHub Desktop.
Bubble Sort
This file contains 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
NSMutableArray *res2 = [[NSMutableArray alloc] initWithArray:@[@2,@34,@452,@45,@234,@6,@3,@1,@343,@543,@23,@2,@34,@452,@45,@234,@6,@3,@1,@343,@543,@23,@2,@34,@452,@45,@234,@6,@3,@1,@343,@543,@23,@2,@34,@452,@45,@234,@6,@3,@1,@343,@543,@23]]; | |
int passnum = res2.count -1 ; | |
BOOL exchange = YES; | |
NSDate *date = [NSDate date]; | |
while (passnum >0 && exchange) { | |
exchange = false; | |
for (int i = 0 ; i < passnum ; i++) | |
{ | |
if([res2[i] integerValue] > [res2[i+1] integerValue]) | |
{ | |
exchange = YES; | |
NSNumber *temp = res2[i]; | |
res2[i] = res2[i+1]; | |
res2[i+1] = temp; | |
} | |
} | |
passnum--; | |
} | |
NSDate *now = [NSDate date]; | |
float diff = [now timeIntervalSince1970] - [date timeIntervalSince1970]; | |
diff = diff * 1000; | |
NSLog(@"%f",diff); | |
//debug mode 0.297070 |
This file contains 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
var res2 = [2,34,452,45,234,6,3,1,343,543,23,2,34,452,45,234,6,3,1,343,543,23,2,34,452,45,234,6,3,1,343,543,23,2,34,452,45,234,6,3,1,343,543,23]; | |
var passnum = res2.count - 1 | |
var exchange = true | |
var date = NSDate.date() | |
while passnum > 0 && exchange | |
{ | |
exchange = false | |
for (var i = 0 ; i < passnum ; i++) | |
{ | |
if(res2[i] > res2[i+1]) | |
{ | |
exchange = true | |
var temp = res2[i] | |
res2[i] = res2[i+1]; | |
res2[i+1] = temp; | |
} | |
} | |
passnum-- | |
} | |
var now = NSDate.date() | |
var diff = now.timeIntervalSince1970 - date.timeIntervalSince1970 | |
diff = diff * 1000 | |
print(diff) | |
//Debug Mode 14.3520832061768 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment