I. Interview and the examination process will appear a sorting algorithm interview questions, in order to deepen the understanding of the sorting algorithm, in this I have a summary of various sorting algorithms to summarize.
1. Bubble sorting algorithm (Bubblesort)
1 PublicClass Sortdemo2 {3 Public voidBubblesort (intarr)4 {5 inttemp=0;6 //need to go to arr. Length-1 Trip7 for(intI=0; I<arr. length-1; i++)8 {9 //number of comparisons required per tripTen for(intj=0, J<arr. length-i-1; j + +) One { A //Sort Ascending - if(arr[j]>arr[j+1]) - { theTEMP=ARR[J];//save a large variable in a temporary variable -arr[j]=arr[j+1]; -arr[j+1]=temp; - } + } - } + A } at}
2. Direct Insert sort (insertionsort)
PublicClass sortdemo{ Public voidInsertionsort (int[] arr) { inttemp=0; //traverse the number to be inserted (starting from the second bit) for(intI=1; I<arr. length;i++) { intj=i-1;//(J is a sorted ordinal of the position to be inserted)//If the sorted number is greater than the number to be inserted, move backward one while(j>=0&&arr[j]>Arr[i]) {Arr[j+1]=Arr[j]; J--; } arr[j+1]=arr[i];//put the number you want to insert into the insertion position } }}
3. Select Sort (selectionsort)
Public void Selectionsort (int[] arr) {
int temp; for (int i=0;i<arr.) length-1;i++)
{
int minval=arr[i];
int minindex=i;
for (int j=i+1;j<arr. length;j++)
{
if (Minval>arr[j])
MINVAL=ARR[J];
Minindex=j;
}
}
Temp=arr[i];
Arr[i]=minval;
Arr[minindex]=temp;
} }}
Interview often test various sorting algorithm summary. (C #)