Skip to content

Instantly share code, notes, and snippets.

@saturngod
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saturngod/935c47cc29bcd1aa90f6 to your computer and use it in GitHub Desktop.
Save saturngod/935c47cc29bcd1aa90f6 to your computer and use it in GitHub Desktop.
Bubble Sort
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
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