Quick actions

cmd+k|ctrl+k

Navigation

Languages

1412C#BubbleSort 

Snippet info

Language

Csharp

Visibility

public

Author

mhcrnl

Created

2018-10-02T08:33:15Z

Updated

2018-10-03T07:02:24Z

using System;

namespace Mhcrnl {
    

    class MainClass {
        
        static void swapp(ref int a, ref int b){
            int temp=a;
            a=b;
            b=temp;
        }
        
        static void bubbleSort(int[] arr){
            bool swapped;
            for (int i=0; i<arr.Length-1; i++){
                swapped = false ;
                for(int j=0; j<arr.Length-i-1; j++){
                    if (arr [j]>arr[j+1]){
                        swapp(ref arr[j], ref arr[j+1]);
                        swapped = true;
                    }
                }
                if (swapped == false) break;
            }
        } 
        
        static void printArray(int[] arr){
            for(int i=0; i<arr.Length; i++){
                Console.Write(arr[i]+" ");
            }
        }
        
        static void Main() {
            Console.WriteLine("Hello World!");
            
            int a=3,b=4;
            Console.WriteLine(a+" "+b);
            swapp(ref a,ref b );
            Console.WriteLine (a+" "+b); 
            
            int[] arr ={ 78,89,2,5,3,23,45};
            bubbleSort (arr );
            printArray(arr);
            
            
        }
    }
}
INFO