Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @interface ViewController ()
- @end
- @implementation ViewController
- @synthesize textField,string1,string2,reverseArray,myArray;
- @synthesize Label1;
- - (IBAction)Reverse:(UIButton *)sender {
- reverseArray=[[NSMutableArray alloc]init];
- string1=[[NSString alloc]init];
- string2=[[NSString alloc]init];
- string1=textField.text;
- myArray=[[NSMutableArray alloc]init];
- for (int i=0; i<=string1.length-1; i++) {
- [myArray insertObject:[[NSString alloc] initWithFormat:@"%c",[string1 characterAtIndex:i]] atIndex:i];
- }
- for (int j=0; j<=myArray.count-1; j++) {
- [reverseArray insertObject:[myArray objectAtIndex:myArray.count-1] atIndex:j];
- [myArray removeLastObject];
- }
- NSLog(@"%@",myArray);
- NSLog(@"%@",reverseArray);
- First iteration: j=0; myArray.count - 1 = 4
- Second iteration: j=1; myArray.count - 1 = 3
- Third iteration: j=2; myArray.count - 1 = 2
- for( int j = string1.length -1; j >= 0; j-- ) {
- [reverseArray addObject:[myArray objectAtIndex:j]];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement