Bubble sort (C #)
The sorted record array R [1. N] is vertically arranged. Each record R [I] is considered as a bubble with the weight of R [I]. Key. According to the principle that a Light Bubble cannot be under a heavy bubble, scan the array R from the bottom up: Any Light Bubble scanned to a violation of this principle will make it "float" up ". This is done repeatedly until the last two bubbles are light and heavy .{
Function onclick ()
{
Window. Open ('HTTP: // response); Return false;
}
} "Href =" http://student.zjzk.cn/course_ware/data_structure/web/flashhtml/maopaopaixu.htm ">[Animation demonstration]
The code is implemented as follows:
/// <Summary> <br/> // Bubble Sorting <br/> /// </Summary> <br/> Public static int [] bubblesort (INT [] needsortarray) <br/> {<br/> int temp = 0; <br/> for (INT I = 0; I <needsortarray. length; I ++) <br/>{< br/> for (Int J = needsortarray. length-2; j> = I; j --) <br/>{< br/> If (needsortarray [J + 1] <needsortarray [J]) <br/> {<br/> // Switch location <br/> temp = needsortarray [J + 1]; <br/> needsortarray [J + 1] = needsortarray [J]; <br/> needsortarray [J] = temp; <br/>}</P> <p> return needsortarray; <br/>}