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
- (NSString *) reverseString:(NSString *)str { | |
NSMutableString *reverseString = [[NSMutableString alloc] initWithCapacity:str.length]; | |
for(int i=str.length -1;i>=0;i--) { | |
[reverseString appendString:[NSString stringWithFormat:@"%c", [str characterAtIndex:i]]]; | |
} | |
return reverseString; | |
} |
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
- (int) atoi:(char *) str { | |
if(!str) | |
NSLog(@"Enter valid string"); | |
int result = 0; | |
char *p = str; | |
while((*p>='0') && (*p<='9')) { | |
result = result*10 + (*p - '0'); | |
p++; | |
} |
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
- (id) sharedInstance { | |
static MyObject *sharedInstance = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
sharedInstance = [[MyObject alloc] init]; | |
}); | |
return sharedInstance; | |
} |
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
- (NSArray*) mergeSortArray:(NSArray*) arr { | |
if(arr.count <2) { | |
return arr; | |
} | |
NSUInteger middle = arr.count/2; | |
NSRange leftRange = {0,middle}; | |
NSArray *leftArray = [arr subarrayWithRange:leftRange]; | |
NSRange rightRange = {middle,arr.count-middle}; | |
NSArray *rightArray = [arr subarrayWithRange:rightRange]; |
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
- (NSArray*) quickSortArray:(NSArray*) arr { | |
if(arr.count <2) { | |
return arr; | |
} | |
NSMutableArray *mutableArr = [arr mutableCopy]; | |
NSMutableArray *leftArray = [[NSMutableArray alloc] init]; | |
NSMutableArray *rightArray = [[NSMutableArray alloc] init]; |
NewerOlder