Hello guys i have a question about my program testing. How do i fill arguments in main(); IList testas = new List(); now its empty , program is running withou errors. Any answer would be a huge help , thanks.
static void Main(string[] args)
{
IList<Node> testas = new List<Node>();
Sort(testas);
}
/// constructor used to assign default element to header
public class Node
{
public int Element;
public Node Link;
// constructor
public Node()
{
Element = 0;
Link = null;
}
// parameterized constructor
public Node(int theElement)
{
Element = theElement;
Link = null;
}
}
public static IList<Node> Sort(IList<Node> input)
{
if (input.Count <= 1) return input;
var midpoint = input.Count / 2;
IList<Node> left = new List<Node>();
IList<Node> right = new List<Node>();
for (var i = 0; i < midpoint; i++)
{
left.Add(input[i]);
}
for (var i = midpoint; i < input.Count; i++)
{
right.Add(input[i]);
}
left = Sort(left); //recursion
right = Sort(right);
return Merge(left, right);
}
private static IList<Node> Merge(IList<Node> left, IList<Node> right)
{
var result = new List<Node>();
while (left.Any() && right.Any())
{
if (Convert.ToInt32(left.First()) < Convert.ToInt32(right.First()))
{
result.Add(left[0]);
left.RemoveAt(0);
}
else
{
result.Add(right[0]);
right.RemoveAt(0);
}
}
while (left.Any())
{
result.Add(left[0]);
left.RemoveAt(0);
}
while (right.Any())
{
result.Add(right[0]);
right.RemoveAt(0);
}
return result;
}