C # Sort Algorithm Daquan

zhaozj2021-02-16  74

First, bubble sorting (bubble)

Using system;

Namespace bubblesorter

{

PUBLIC CLASS BUBBLESORTER

? {

?? public void sort (int [] list)

?? {

??? INT i, J, TEMP;

??? bool done = false;

??? j = 1;

??? while ((j ??? {

???? done = true;

???? for (i = 0; i ???? {

????? f (list [i]> list [i 1])

????? {

????? done = false;

????? Temp = List [i];

????? list [i] = list [i 1];

????? List [i 1] = TEMP;

?????}

????}

??? j ;

???}

??}

?

PUBLIC CLASS MainClass

? {

?? public static void main ()

?? {

??? int [] IARRARY = new int = {1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47};

??? bubblesorter sh = new bubblesorter ();

??? Sh.sort (IARRARY);

??? for (int m = 0; m ??? console.write ("{0}", IARRARY [M]);

??? console.writeline ();

??}

?

}

Second, choose sorting (SELECTION)

Using system;

Namespace SelectionsRerter

{

Public Class SelectionsRerter

? {

?? private int min;

?? public void sort (int [] list)

?? {

??? for (int i = 0; i ??? {

??? min = i;

???? for (int J = i 1; j ???? {

???? i (list [j] ???? min = j;

????}

??? INT T = List [min];

??? list [min] = list [i];

??? list [i] = t;

???}

??}

?

PUBLIC CLASS MainClass

? {

?? public static void main ()

?? {

??? int [] IARRARY = new int = {1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47};

??? SelectionsORTER SS = New Selections Porter ();

??? ss.sort (IARRARY);

??? for (int m = 0; m ??? console.write ("{0}", IARRARY [M]);

??? console.writeline ();

??}

?

}

Using system;

Namespace InsertionsRionSorter

{

PUBLIC CLASS INSERTIONSORTER

? {

?? public void sort (int [] list)

?? {

??? for (int i = 1; i ??? {

??? INT T = List [i];

??? INT j = i;

???? while ((j> 0) && (list [j-1]> t))

???? {

???? list [j] = list [j-1];

???? - j;

????}

??? list [j] = t;

???}

??}

?

PUBLIC CLASS MainClass? {

?? public static void main ()

?? {

??? Int [] IARRARY = new int = {1, 13, 3, 6, 10, 55, 98, 2, 87, 12, 34, 75, 33, 47};

??? INSERTIONSORTER II = New INSERTIONSORTER ();

??? II.sort (IARRARY);

??? for (int m = 0; m ??? console.write ("{0}", IARRARY [M]);

??? console.writeline ();

??}

?

}

Four, Hill Sort (SHELLSORTER)

Using system;

Namespace shellsorter

{

Public Class Shellsorter

? {

?? public void sort (int [] list)

?? {

?? int INC;

?? for (inc = 1; inc <= list.length / 9; inc= 3 * inc 1);

??? for (; inc> 0; inc / = 3)

??? {

???? for (int i = inc 1; i <= list.length; i = inc)

???? {

???? INT T = List [i-1];

???? INT j = i;

????? while ((j> inc) && (list [j-inchem-1]> t))

????? {

????? list [j-1] = list [j-inchem-1];

????? j- = inc;

?????}

???? list [j-1] = T;

????}

???}

??}

?

PUBLIC CLASS MainClass

? {

?? public static void main ()

?? {

??? int [] IARRARY = new int = {1, 5, 13, 6, 10, 55, 99, 2, 87, 12, 34, 75, 33, 47};

??? shellsORTER SH = New shellsorter ();

??? Sh.sort (IARRARY);

??? for (int m = 0; m ??? console.write ("{0}", IARRARY [M]);

??? console.writeline ();

??}

?

}?

转载请注明原文地址:https://www.9cbs.com/read-13884.html

New Post(0)