Beispiel #1
0
        static void Main(string[] args)
        {
            //Create a linked list of type int
            var list = new LinkedList <int>();

            try
            {
                //Read the first line of the text file with the numbers and split by ','
                string       numbers;
                StreamReader inputFile = new StreamReader("C:\\numbers.txt");
                numbers = inputFile.ReadLine();
                string[] split = numbers.Split(',');
                //Add the numbers to the list
                for (int i = 0; i <= 9; i++)
                {
                    if (split[i] == " ")
                    {
                        break;
                    }
                    list.AddLast(Convert.ToInt32(split[i]));
                }
                //Close the input
                inputFile.Close();
                //Create a sorted version of the list and display it
                var listOrdered = list.OrderBy(i => i);
                foreach (var item in listOrdered)
                {
                    Console.Write(item + "  ");
                    Console.WriteLine();
                }
                running(listOrdered);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error reading file.");
                Console.ReadKey();
            }
        }