title: insertion sort algorithm in Objective-C to implement in iphone
body: <p>I am trying to sort 15 random numbers using Objective-C in the code shown below. The code is not working as planned. I took the concept from the the insertion sort C code. The 15 random numbers are generating properly but the sort is not working.</p>
  
  <p><strong>C code:</strong></p>
  
  <pre><code>int i, j, index;
  for (i = 1; i &lt; array_size; ++i)
  {
    index = a[i];
    for (j = i; j &gt; 0 &amp;&amp; a[j-1] &gt; index; j--)
      a[j] = a[j-1];
  
    a[j] = index;
  }
  </code></pre>
  
  <p><strong>Objective-C code:</strong> </p>
  
  <pre><code>-(IBAction)clicked_insertsort:(id)sender
  {
    NSMutableArray *array = [NSMutableArray array];
    for (int x = 0; x &lt; 15; x++) 
    {
      [array addObject: [NSNumber numberWithInt: arc4random()%200]];
    }
    NSLog(@"%@",array);
    {
      int i, j;
      id index;
      for (i = 1; i &lt; 15; ++i)
      {
        index = [array objectAtIndex:(NSUInteger)i]; //   a[i];
        for (j = i; j &gt; 0 &amp;&amp; [array objectAtIndex:(NSUInteger)j-1] &gt; index; j--)
          [array replaceObjectAtIndex: (j) withObject: [array objectAtIndex: (j-1)]];
  
        [array objectAtIndex:(NSUInteger)j] == index ;
      }
    }
    NSLog(@"%@",array);   
  }
  </code></pre>