Namespace Bubblesorter
{
public class Bubblesorter
{
public void Sort (int [] list)
{
int i,j,temp;
BOOL Done=false;
J=1;
while (j<list. Length) && (!done))
{
Done=true;
For (i=0;i<list. length-j;i++)
{
If (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<iarrary.length;m++)
Console.Write ("{0}", Iarrary[m]);
Console.WriteLine ();
}
}
}
Select sort
I used C # to develop a select sorting algorithm. I hope I can bring some benefits to the C # language learners. Don't forget, learning languages takes a lot of effort to learn data structures and algorithms.
Using System;
Namespace Selectionsorter
{
public class Selectionsorter
{
private int min;
public void Sort (int [] list)
{
for (int i=0;i<list. length-1;i++)
{
Min=i;
for (int j=i+1;j<list. length;j++)
{
if (List[j]<list[min])
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 Selectionsorter ();
Ss. Sort (iarrary);
for (int m=0;m<iarrary.length;m++)
Console.Write ("{0}", Iarrary[m]);
Console.WriteLine ();
}
}
}
Insert Sort
Inserts a sort algorithm. We can talk to friends who want to improve the ability of C # language programming. Such as: The following program, and did not realize polymorphism, to help it achieve a bit.
Using System;
Namespace Insertionsorter
{
public class Insertionsorter
{
public void Sort (int [] list)
{
for (int i=1;i<list. length;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<iarrary.length;m++)
Console.Write ("{0}", Iarrary[m]);
Console.WriteLine ();
}
}
}
Hill sort
The hill sort is to insert the component segments into the sort. We can talk to friends who want to improve the ability of C # language programming. Such as: The following program, and did not realize polymorphism, to help it achieve a bit.
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-inc-1]>t))
{
LIST[J-1]=LIST[J-INC-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<iarrary.length;m++)
Console.Write ("{0}", Iarrary[m]);
Console.WriteLine ();
}
}
}
I only now find that some things are immutable, such as algorithms.
The basic algorithm implemented in C # is very good, is not indented, I typesetting for a long time did not line up, depressed ing
Now it's time to do it. You should be able to see clearly.
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.