JOIN
Get Time
forums   
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
Psuedo code for bubble sort seems to be incorrect. | Reply
Psuedo code in tutorial:
for (int i = 0; i < data.Length; i++)
   for (int j = 0; j < data.Length - 1; j++)
      if (data[j] > data[j + 1])
      {
         tmp = data[j];
         data[j] = data[j + 1];
         data[j + 1] = tmp;
      }

1st line (outer for loop) should be
for (int i = 0; i < data.Length - 1; i++)

2nd line (inner for loop) should be
  for(int j=0; j < data.Length - i - 1; j++)
Re: Psuedo code for bubble sort seems to be incorrect. (response to post by foxtrot9) | Reply
Sorry for re-posting this equation again, this issue has been discussed here: https://apps.topcoder.com/forums/?module=Thread&threadID=513448&start=0
RSS