Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

bubble sort in c#

public static void Sort<T>(T[] array) where T : IComparable 
{
    for (int i = 0; i < array.Length; i++)
    {
        for (int j = 0; j < array.Length - 1; j++) 
        {
            if (array[j].CompareTo(array[j + 1]) > 0) 
            {
            	Swap(array, j, j + 1); 
            } 
        }
    }
}
private static void Swap<T>(T[] array, int first, int second) 
{
	T temp = array[first];
  	array[first] = array[second];
  	array[second] = temp;
}
Comment

bubble dort c#

int[] arr = { 800, 11, 50, 771, 649, 770, 240, 9 };

int temp = 0;

for (int write = 0; write < arr.Length; write++) {
    for (int sort = 0; sort < arr.Length - 1; sort++) {
        if (arr[sort] > arr[sort + 1]) {
            temp = arr[sort + 1];
            arr[sort + 1] = arr[sort];
            arr[sort] = temp;
        }
    }
}

for (int i = 0; i < arr.Length; i++)
    Console.Write(arr[i] + " ");

Console.ReadKey();
Comment

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
Comment

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();
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# connect to mongodb 
Csharp :: how to stop rigidbody2d from falling in unity 
Csharp :: prettier isnt working c# 
Csharp :: c# datagridview change column name 
Csharp :: wpf scrollviewer mouse wheel 
Csharp :: c# encrypt decrypt string 
Csharp :: unity 2d joystick controls 
Csharp :: ggdesign 
Csharp :: boostrap 4 modal 
Csharp :: mvc list to jsonresult 
Csharp :: get name of project c# .net 
Csharp :: wpf get screen size 
Csharp :: Prevent player rotation unity 
Csharp :: array.convertall 
Csharp :: c# for loop increment by 2 
Csharp :: generate random name c# 
Csharp :: color picker wpf 
Csharp :: c# get user appdata folder 
Csharp :: csproj include folder and files 
Csharp :: c# compile code at runtime 
Csharp :: deserialize object to dictionary c# 
Csharp :: covert char[] to string C# 
Csharp :: c# listbox delete selected items 
Csharp :: dotnet new project 
Csharp :: how to set the frame rate unity 
Csharp :: c# using file.io 
Csharp :: run wpf application maximized 
Csharp :: create line in unity 
Csharp :: c# how to sort a list 
Csharp :: rotate player unity 2d left and right 
ADD CONTENT
Topic
Content
Source link
Name
7+7 =