冒泡排序
本人用了C#开发出冒泡排序算法。希望能为C#语言的学习者带来一些益处。不要忘了,学语言要花大力气学数据结构和算法。 - <div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">using System</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font>
- </div><div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">namespace BubbleSorter
- {
- public class BubbleSorter
- {
- public void Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int [] list</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int i,j,temp</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- bool done=false</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- j=1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- while</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">((</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">&&</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">!done</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">))</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- done=true</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i=0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list.Length-j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- if</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list<i></i></font></font></font><i><i><font color="black"><font face="宋体"><font style="font-size: 11pt; ">></font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list[i+1]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- done=false</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- temp=list<i></i></font></font></font><i><i><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- list<i>=list[i+1]</i></font></font></font><i><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- list[i+1]=temp</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- }
- j++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }</font></font></font></i></i></i></i></i></div><div align="left"><i><i><i><font color="black"><font face="Arial"><font style="font-size: 11pt; ">}
- }
- public class MainClass
- {
- public static void Main</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">()</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47}</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- BubbleSorter sh=new BubbleSorter</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- sh.Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int m=0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.Write</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">"{0} ",iArrary[m]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.WriteLine</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- }
- }</font></font></font></i></i></i></div>
复制代码 |
选择排序
本人用了C#开发出选择排序算法。希望能为C#语言的学习者带来一些益处。不要忘了,学语言要花大力气学数据结构和算法。 - <div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">using System</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font></div><div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">namespace SelectionSorter
- {
- public class SelectionSorter
- {
- private int min</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- public void Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int [] list</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int i=0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list.Length-1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- min=i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int j=i+1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">j++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- if</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list[j]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list[min]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- min=j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- int t=list[min]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- list[min]=list<i></i></font></font></font><i><i><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- list<i>=t</i></font></font></font><i><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }</font></font></font></i></i></i></div><div align="left"><i><i><i><font color="black"><font face="Arial"><font style="font-size: 11pt; ">}
- }
- public class MainClass
- {
- public static void Main</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">()</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int[] iArrary=new int[]{1,5,3,6,10,55,9,2,87,12,34,75,33,47}</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- SelectionSorter ss=new SelectionSorter</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- ss.Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int m=0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.Write</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">"{0} ",iArrary[m]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.WriteLine</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font></i></i></i></div><div align="left"><i><i><i><font color="black"><font face="Arial"><font style="font-size: 11pt; ">}
- }
- }</font></font></font></i></i></i></div>
复制代码 |
插入排序
插入排序算法。对想提高C#语言编程能力的朋友,我们可以互相探讨一下。如:下面的程序,并没有实现多态,来,帮它实现一下。 - <div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">using System</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font></div><div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">namespace InsertionSorter
- {
- public class InsertionSorter
- {
- public void Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int [] list</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int i=1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int t=list<i></i></font></font></font><i><i><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- int j=i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- while</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">((</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">></font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">&&</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list[j-1]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">></font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">t</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">))</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- list[j]=list[j-1]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- --j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- list[j]=t</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }</font></font></font></i></i></div><div align="left"><i><i><font color="black"><font face="Arial"><font style="font-size: 11pt; ">}
- }
- public class MainClass
- {
- public static void Main</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">()</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int[] iArrary=new int[]{1,13,3,6,10,55,98,2,87,12,34,75,33,47}</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- InsertionSorter ii=new InsertionSorter</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- ii.Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int m=0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.Write</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">"{0}",iArrary[m]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.WriteLine</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- }
- }</font></font></font></i></i></div>
复制代码 |
希尔排序
希尔排序是将组分段,进行插入排序. 对想提高C#语言编程能力的朋友,我们可以互相探讨一下。如:下面的程序,并没有实现多态,来,帮它实现一下。 - <div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">using System</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font>
- </div><div align="left"><font color="black"><font face="Arial"><font style="font-size: 11pt; ">namespace ShellSorter
- {
- public class ShellSorter
- {
- public void Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int [] list</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int inc</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">inc=1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">inc</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">=list.Length/9</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">inc=3*inc+1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">inc</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">></font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">inc/=3</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int i=inc+1</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">=list.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">i+=inc</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int t=list[i-1]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- int j=i</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- while</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">((</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">j</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">></font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">inc</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">&&</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">list[j-inc-1]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">></font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">t</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">))</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- list[j-1]=list[j-inc-1]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- j-=inc</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- list[j-1]=t</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- }
- }
- }
- public class MainClass
- {
- public static void Main</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">()</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- {
- int[] iArrary=new int[]{1,5,13,6,10,55,99,2,87,12,34,75,33,47}</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- ShellSorter sh=new ShellSorter</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- sh.Sort</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- for</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">int m=0</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; "><</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">iArrary.Length</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">;</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">m++</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">)</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.Write</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">(</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">"{0} ",iArrary[m]</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">);</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- Console.WriteLine</font></font></font><font color="black"><font face="宋体"><font style="font-size: 11pt; ">();</font></font></font><font color="black"><font face="Arial"><font style="font-size: 11pt; ">
- }
- }
- }</font></font></font></div>
复制代码 |
|