Bubble sort (C #)

Source: Internet
Author: User
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/>}

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.