“Csharp Bubble Sort” Ответ

C# Bubble Sort

// C# program for implementation 
// of Bubble Sort
using System;
  
class GFG
{ 
    static void bubbleSort(int []arr)
    {
        int n = arr.Length;
        for (int i = 0; i < n - 1; i++)
            for (int j = 0; j < n - i - 1; j++)
                if (arr[j] > arr[j + 1])
                {
                    // swap temp and arr[i]
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
    }
  
    /* Prints the array */
    static void printArray(int []arr)
    {
        int n = arr.Length;
        for (int i = 0; i < n; ++i)
            Console.Write(arr[i] + " ");
        Console.WriteLine();
    }
  
    // Driver method
    public static void Main()
    {
        int []arr = {64, 34, 25, 12, 22, 11, 90};
        bubbleSort(arr);
        Console.WriteLine("Sorted array");
        printArray(arr);
    }
  
}
  
// This code is contributed by Sam007
Dentetsu

Csharp Bubble Sort

using System;

public class Program {
   	//Bubble sort function
    private static float[] BubbleSort(float[] Array){
        bool Sorted = false;

        while (!Sorted){
            Sorted = true;
            for (int i = 0; i < Array.Length-1; i++)
            {
                if (Array[i] > Array[i+1]){
                    //swap Array[i] and Array[i+1]
                  	Sorted = false;
                    float Temp = Array[i+1];
                    Array[i+1] = Array[i];
                    Array[i] = Temp;
                }
            }
        }
        return Array;
    }
    public static void Main() {
        float[] UnSortedList = {1,56,3,6,7,543,542,1,555,4,1091};
        float[] SortedList = BubbleSort(UnSortedList);
		//prints the Sorted array
      	for (int i = 0; i < SortedList.Length; i++)
        {
            Console.Write(SortedList[i] + " ");
        }
        Console.ReadKey();
    }
}
Homely Herring

Ответы похожие на “Csharp Bubble Sort”

Вопросы похожие на “Csharp Bubble Sort”

Смотреть популярные ответы по языку

Смотреть другие языки программирования