Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7698333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:13:01+00:00 2026-05-31T22:13:01+00:00

I want to sort array using Bubble Sort. I an missing a small point

  • 0

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;  
       }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T22:13:02+00:00Added an answer on May 31, 2026 at 10:13 pm

    If this is for an academic exercise (why else would you use Bubble sort?) then please refer to other posters’ responses.

    If this is for code to be used in the real world, be aware that Bubble Sort is a very slow sorting method, and not generally recommended for anything beyond a learning tool.

    Big O notation is one means of describing the time complexity of sorting algorithms. Bubble Sort’s time complexity is O(n2), which means that the time will be a function of the square of the number of elements being sorted, i.e. extremely slow for more than a few elements.

    In general, you should be using built-in sort methods wherever possible, as these will have been optimised to sort much more quickly.

    This post describes the built-in methods for sorting in iOS, which have the added benefit of being far more concise and readable, as well as being much faster than Bubble Sort.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the following ASM routine to bubble sort an array. I want
I want to sort array of random numbers using MPI library. The idea is
I am trying to sort an array of integers in MIPS using bubble sort
I have an array of objects which I want to sort based on one
I want to sort an array by using uasort() function. I wrote this piece
Hi I have a generic bubble sort algorithm which I am using and I
I want to sort array A based on values in Array B actually in
How can I sort a 2D array in PHP. I want to sort on
I have an array that I want to sort based on the value of
I want to sort a flat, associative array by its values alphabetically and preserve

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.