Ritesh Singh
Sort the given array using the bubble sort? int[] a = { 8, 3, 11, 34, 43, 1, 67, 35, 98 };
By Ritesh Singh in .NET on Aug 13 2016
  • Ritesh Singh
    Aug, 2016 13

    public int[] min(int[] a){int temp, swaps;for (int i = 0; i < a.Length; i++){swaps = 0;for (int j=0;j a[j + 1]){temp = a[j];a[j] = a[j+1];a[j + 1] = temp;swaps++;}}if (swaps == 0){break;}}return a;}

    • 1
  • Dinuka Hettiarachchi
    Nov, 2021 18

    1. public static string BubbleSort()
    2. {
    3. int[] arr = { 78, 55, 45, 98, 13 };
    4. int temp;
    5. for (int j = 0; j <= arr.Length - 2; j++)
    6. {
    7. for (int i = 0; i <= arr.Length - 2; i++)
    8. {
    9. if (arr[i] > arr[i + 1])
    10. {
    11. temp = arr[i + 1];
    12. arr[i + 1] = arr[i];
    13. arr[i] = temp;
    14. }
    15. }
    16. }
    17. Console.WriteLine("Sorted:");
    18. foreach (int p in arr)
    19. Console.Write(p + " ");
    20. Console.Read();
    21. }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS