I want to sort array using Bubble Sort. I an missing a small point due to which array is not sorted properly. I would highly appreciate if somebody can figure out the issue.
int i,k;    
int flag = 1;   
MReview *store1 ,*store2,*tempSwap;  
tempSwap = [[MReview alloc] init];  
store1 = [[MReview alloc] init];  
store2 = [[MReview alloc] init];  
for (i = 1;i <= ([arrSortWeeks count]) && flag; i++)
{  
    NSLog(@"Next Iteration: %d", i+1);  
    flag = 0;  
    for (k = 0;   k < ([arrSortWeeks count]-1);   k++)
    {
      store1 = [arrSortWeeks objectAtIndex:k+1];   
      store2 = [arrSortWeeks objectAtIndex:k];  
      //Confronto returns -1 if Store1 is greater and returns 1 if Store1 is smaller
      if (([self confronto:store1.ReviewDate :store2.ReviewDate]) == -1) 
      {    
         tempSwap = store2;  
         store2 = store1;  
         store1 = tempSwap;  
         //[store1 retain];  
         //[store2 retain];  
         [arrSortWeeks replaceObjectAtIndex:k+1 withObject:store1];  
         [arrSortWeeks replaceObjectAtIndex:k withObject:store2];
         flag = 1;  
       }
    }
}
 
     
     
     
    