מרץ.05

מיון בועות - bubble sort

מיון בועות - bubble sort

אוק, זה פשוט, כולם יודעים.... אבל איך?

public int[] BubbleSort(int[] intArray) {
    for (int i = intArray.Length - 1; i > 0; i--)
            {
                for (int j = 0; j <= i - 1; j++)
                {
                    if (intArray[j] > intArray[j + 1])
                    {
                        int highValue = intArray[j];
 
                        intArray[j] = intArray[j + 1];
                        intArray[j + 1] = highValue;
                    }
                }
            }
    return intArray;
}
תגיות:
שתף את הסיפור הזה:

תגובות(1)

  1. מריה
    לפני יותר משנה
    כמובן, שזמן ריצה יהיה (O(n^2

השאירו תגובה

קפטצ'ה לא מתאימה

תגובה