]=Vec[min]; Vec[min]=temp; } } }3. Insert sort, thought: Each time the collection is never sorted, take an element into the already sorted array, notice the difference between using the array and judging the condition with the vectorvoidInsertsort (vectorint>vec,intN//The reference must be passed here, because this is a class object, unlike an array{ if(vec = =NULL)return; intkey; for(inti =1; I ) {Key= Vec[i];//staging the value to insert
The code looks like this:
Copy Code code as follows:
/*
*
Bubble Sort*/
void Bubblesort (int arr[], int n)
{
int temp;
for (int i = 0; i {
for (int j = i + 1; j {
if (Arr[i] > Arr[j])
{
temp = Arr[i];
Arr[i] = Arr[j];
ARR[J] = temp;
}
}
}
}
/*
*
Select Sort*/
void Choosesort (int arr[], int n)
{
int temp, k;
for (int i = 0; i {
Bubble Sort in PHP, select Sort, insert sort
?? Bubble sort
?? Function Bubblesort ( $arr) {
????
???? $temp = 0;
????
???? Add maximum number of first
???? for ($i =0; $i
??????
?????? for ($j =0; $j
1. Use the sort () in the arrays class in the Javaapi document to sort quickly
Copy Code code as follows:
Import Java.util.Arrays;
public class testone{
public static void Main (String [] args) {
int [] array={2,0,1,4,5,8};
Arrays.sort (array);//Call Arrays static method sort, sorted in ascending order
for (int show:array) {
Sy
Sort:
Public class sortdemo {public static void main (string [] ARGs) {int [] arr = {5, 8, 9, 12, 55,565,421, 12,251 2,-5, -56}; // int [] arr = {6, 9, 4589,442,458,523 2,-788, 7,545,-44, 55,-11 //}; // selectionsort (ARR); // bubblesort (ARR); directinsertsort (ARR); printsort (ARR );} // select sorting. Each trip determines the number of ARR [I]. Each time the number of ARR [I] is equal to the number of all the following arr [J]. If the number is sa
Insert SortThe idea of inserting a sort is to traverse the entire array starting from the second element of the array. For each element, the elements that precede it are compared to him, the elements that are greater than it are moved backwards, and the element is finally inserted.The insertion sort is a stable sorting algorithm.Time Complexity T (n) =o (n^2)The best case has been ordered, T (n) =o (n)priv
Material: Monkey sort, according to height from small to large to sort.First Pass:The old monkeys led the small monkeys team by the size of a comparison, exchange, began to height ranks. (Bubble sort)Second Pass:Too slow, to make the first level more difficult, select sortThird Pass:Finally, try to sort by using the In
Recently looking at data structure and algorithm analysis, want to write a note to record, first from the basic bubble, select, insert Start.
Note: This is illustrated by the example of the increment sequence
First, bubble sort
1, principle: Starting from the first position of the array 22 compare Array[index] and array[index+1], if ARRAY[INDEX] greater than arra
Two days ago just loaded Python 3.1.1, can't help itched write point code.1. Select sort
Copy Code code as follows:
>>> def selsort (L):
Length=len (L)
For I in Range (length-1):
Minidx=i
Minval=l[i]
J=i+1
While JIf MINVAL>L[J]:
Minidx=j
MINVAL=L[J]
J=j+1
L[i],l[minidx]=l[minidx],l[i]
Return L
2. Bubble sort
Cop
The working mechanism of the insertion sort and the arrangement of the rows in the hand when playing cards are similar. In the beginning, our left hand is empty, the ranking is down on the table, then, one hand from the table to touch a card, and put it in the right hand row of the correct position. In order to find the correct position of this card, he and his hands do not have a oh from the right to the left to compare, no matter what time, the left
using the Novice's thinking learning algorithm--toilet sort, bubble sort and quick sort"Bo Master" anti-bone Aberdeen "source" http://www.cnblogs.com/liqingwen/p/4994261.htmlToilet Sortfirst, the scene : The final exam is over, the teacher to the students score from high to low sor
From today began to hope that their blog can continue to update, because I have limited capacity, so some content may be overlooked or incomplete, I hope you can point out, let us learn together, progress together.Today's content is the simplest of three sorting algorithms, bubble sort, select sort, insert sort, and th
Sort algorithm------Bubble sort bubblesortBubble sort is the most basic sort method, it is through the large number of precipitation, not a round of sequencing, the entire sequence of the largest number will be placed in the end, "bubbling is the final appearance of this num
Simple sorting (after learning to review in time, otherwise like not to learn the same, andSpend more time in the future)Bubble sort: small number upBubble sort (bubblesort) is a repeated visit to the sorted sequence,Compare two elements at a time, if they are in the wrong order, just put them onSwap them over. The work of the sequence of visits is repeated until
I. Sorting algorithm definition1. Sorting calculation definitionSorting algorithm is a kind of algorithm that can arrange a string of data according to a certain order2. Six kinds of sorting algorithms to understand the wayImagine when the teacher gave us in line with the height of the method used in the brain to appear in the height of the teacher to the scene in order from low to high for example 3. Definition of stabilityA sorting algorithm is stable when there are two equal key values for t
Bubble sort is the most basic sorting algorithm in the sorting algorithm.The principle is that the adjacent number 22 is compared and exchanged in order from small to large or from large to smallPackage Com.neuedu.java; Public classBubblesort { Public Static voidMain (string[] args) {int[] arr=New int[]{0,9,5, $, A,94, About,7}; Bubblesort (arr); for(intI=0; i) {System. out. Print (arr[i]+" "); }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.