using System;
using System.Collections.Generic;
using System.Text;
namespace Algorithms
{
    public class LinkedList
    {
        private Node head;
        public LinkedList()
        {
            head = null;
        }
        public void Sort()
        {
            if (head != null)
            {
                int j = 0;
                Node MinElement = head;
                Node currentElement = MinElement.NextNode;
                while (currentElement != null)
                {
                   
                    if (currentElement.DataValue < MinElement.DataValue)
                    {
                        MinElement = currentElement;
                        Insert(MinElement.DataValue);
                        DeleteAtPosition(j+1);
                    }
                MinElement = MinElement.NextNode;
                }
            }
        }
       
    }
    public class Node
    {
        private int dataValue;
        private Node nextNode = null;
        public Node(int data)
        {
            dataValue = data;
        }
        public Node NextNode
        {
            get
            {
                return nextNode;
            }
            set
            {
                nextNode = value;
            }
        }
        public int DataValue
        {
            get
            {
                return dataValue;
            }
            set
            {
                dataValue = value;
            }
        }
    }
}
Sunday, February 25, 2007
Linked List SORT Algorithm
If you need a sort algorithm in Linked List. Please check other implementation in my last blog. 
Labels:
CSharpTricks,
DataStructures
Subscribe to:
Post Comments (Atom)
 
No comments:
Post a Comment