first, bubble sort
Code implementation:
public class Test_bubblesort {public
static void Main (string[] args) {
int[] arr = {23,56,15,13,36};
Bubblesort (arr);
Print (arr);
}
Bubble sort public
static void Bubblesort (int[] arr) {for
(int i = 0;i <arr.length-1; i++) {for
(int j = 0; J &L T Arr.length-1-i; J + +) {
if (Arr[j] > Arr[j+1]) {
int temp = arr[j];
ARR[J] = arr[j+1];
ARR[J+1] = temp;
Swap (arr,i,j+1);
}}}} Print
private static void print (int[] arr) {for
(int i = 0;i < arr.length;i++) {
System.out.println (arr[ I]);
}
Convert public
static void Swap (int[] Arr,int i,int j) {
int temp = arr[i];
Arr[i] = arr[j];
ARR[J] = temp;
}
}
The time complexity of the algorithm is O (n^2), and the space complexity is O (1).
Second, select the sort
Code implementation:
public class test_selectsort{public
static void Main (string[] args) {
int[] arr = {4,7,2,9,0,5};
Selectsort (arr);
Print (arr);
}
Select sort public
static void Selectsort (int[] arr) {for
(int i = 0; i < arr.length-1; i++) {for
(int j = i+1; J < Arr.length; J + +) {
if (Arr[i] > Arr[j]) {
int temp = arr[i];
Arr[i] = arr[j];
ARR[J] = temp;
Swap (ARR,I,J);
}}}} Print public
static void print (int[] arr) {for
(int k =0;k<arr.length;k++)
{
System.out.println (Arr[k]);
}
Transposition operation
private static void Swap (int[] Arr,int i,int j) {
int temp = arr[i];
Arr[i] = arr[j];
ARR[J] = temp;
}
}
The time complexity of the algorithm is O (n^2), and the space complexity is O (1).