Advertisement
NanoBob

C# Bubble sort

Oct 20th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.81 KB | None | 0 0
  1.  public void BubbleSort()
  2.         {
  3.             DoubleLink lastEnd = new DoubleLink();
  4.             while (lastEnd != null)
  5.             {
  6.                 Boolean swapped = false;
  7.                 DoubleLink link = First;
  8.                 while (link !=null){
  9.                     if (link == Last || link == lastEnd)
  10.                     {
  11.                         lastEnd = link;
  12.                         break;
  13.                     }
  14.                     if (link.Naw.CompareTo(link.Next.Naw) == 1)
  15.                     {
  16.                         SwapLinkWithNext(link);
  17.                         swapped = true;
  18.                     }
  19.                     link = link.Next;
  20.                 }
  21.                 if (swapped == false )
  22.                 {
  23.                     break;
  24.                 }
  25.             }
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement