Bubble sort 1: Public voidRisepot (ref int[] Array) { intA =Array. Length; for(inti =0; I < A-1; i++) { for(intj = A-1; J > i; j--) { if(Array[i] >Array[j]) { inttemp =Array[i]; Array[i]=Array[j]; ARRAY[J]=temp; }}}} bubble sort 2: Public voidRisepot (ref int[] Array) { intA =Array. Length; for(inti =0; I < A-1; i++) { for(intj = i+1; J <a; J + +) { if(Array[i] >Array[j]) { inttemp =Array[i]; Array[i]=Array[j]; ARRAY[J]=temp; }}}} Quick sort: Public voidQuickSort (ref int[] arr,intLow,intHigh ) { if(Low <High ) { intMID =Getmid (arr, low, high); QuickSort (refArr, Low, mid-1); QuickSort (refArr, Mid +1, high); } } Public intGetmid (int[] Array,intLowintHigh ) { inttemp =Array[low]; while(Low <High ) { while(Low < High && Array[high] >=temp) { High--; } if(Low <High ) {Array[low]=Array[high]; Low++; } while(Low < High && Array[low] <=temp) { Low++; } if(Low <High ) {Array[high]=Array[low]; High--; }} Array[low]=temp; returnLow ; Do not use a third variable to exchange values of two integersStatic voidMain (string[] args) { intA =1234, B =6666; Swap (refArefb); Console.WriteLine ("{0},{1}", A, b); Console.read (); } Static voidSwap (ref intAref intb) {a= B-A; b= B-A; A= A +b; }
Bubble sort and quick sort