Created
January 9, 2021 10:38
-
-
Save YonLiud/57d1cf64a81fad9e78ad09597ecb447f to your computer and use it in GitHub Desktop.
Sort Node<T> LinkedList, Merge Sort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Node<int> SortInput() | |
{ | |
Console.WriteLine("Insert Value | Insert '-999' to stop"); | |
int value = int.Parse(Console.ReadLine()); | |
Node<int> node = new Node<int>(value); | |
while (value != -999) | |
{ | |
node.SetNext(new Node<int>(value)); | |
Console.WriteLine("Insert Value | Insert '-999' to stop"); | |
value = int.Parse(Console.ReadLine()); | |
node = node.GetNext(); | |
} | |
return Sort(node); | |
} | |
static Node<int> Sort(Node<int> node) | |
{ | |
while(node.HasNext()) | |
{ | |
Node<int> temp; | |
if(node.GetValue() >= node.GetNext().GetValue()) | |
{ | |
temp = node; | |
node = node.GetNext(); | |
node.SetNext(temp); | |
} | |
node = node.GetNext(); | |
} | |
return node; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment