0

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;
    }
Nga Đỗ
  • 29
  • 7
  • suggests you to change the title of your question – Eduardo Portal Geroy May 21 '16 at 00:15
  • Laurynas, I've updated title / closed as duplicate based on possible interpretation of your problem. If you still have a questions - ask new one and make sure to provide better explanation and [MCVE] (pay attention to **Minimal** - 99% of code in this post are not related to question) – Alexei Levenkov May 21 '16 at 00:21
  • IList testas = new List(); how to fill this one with arguments i mean :D like {1,2,3,5,6,8} etc ;) – Laurynas Užupis May 21 '16 at 01:49

1 Answers1

0
string[] args

Is a space separated input, on your console you must write something like

> miprogram.exe value1 4 other_value

that will result on an argument input

args[0] wil be equals to "value1"
args[1] wil be equals to "4"
args[2] wil be equals to "other_value"

you can cast and do all kind of things.

hope it helps