Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public DoubleLink SwapLinkWithNext(DoubleLink link)
- {
- DoubleLink next = link.Next;
- if (next == null)
- {
- return null;
- }
- DoubleLink previous = link.Previous;
- DoubleLink current = link;
- DoubleLink nextNext = next.Next;
- current.Next = nextNext;
- current.Previous = next;
- next.Previous = previous;
- next.Next = current;
- if (previous == null)
- {
- First = next;
- } else {
- previous.Next = next;
- }
- if (nextNext == null)
- {
- Last = current;
- } else {
- nextNext.Previous = current;
- }
- return next;
- }
- public void BubbleSort()
- {
- DoubleLink lastEnd = new DoubleLink();
- while (lastEnd != null)
- {
- Boolean swapped = false;
- DoubleLink link = First;
- while (link !=null){
- if (link == Last || link == lastEnd)
- {
- lastEnd = link;
- break;
- }
- if (link.Naw.CompareTo(link.Next.Naw) == 1)
- {
- SwapLinkWithNext(link);
- swapped = true;
- }
- link = link.Next;
- }
- if (swapped == false )
- {
- break;
- }
- }
- }
Add Comment
Please, Sign In to add comment