public static void MergeSort(this ISimpleList <int> list)
        {
            var result = SplitAndMerge(list, 0, list.Count - 1);

            list.Clear();
            foreach (var value in result)
            {
                list.Add(value);
            }
        }
        public static void HeapSort(this ISimpleList <int> list)
        {
            var heap = new SimpleHeap <int>();

            foreach (var value in list)
            {
                heap.Insert(value);
            }
            list.Clear();
            while (heap.Count > 0)
            {
                list.Add(heap.RemoveTop());
            }
        }
Ejemplo n.º 3
0
        public string[] Run(ISimpleList <String> array, string[] input)
        {
            var instructions = input;

            foreach (var instruction in instructions)
            {
                char   command = instruction[0];
                String value   = instruction.Substring(1);
                switch (command)
                {
                case '+':
                    array.Add(value);
                    break;

                case '-':
                    array.RemoveAt(Int32.Parse(value));
                    break;

                case '~':
                    array.Clear();
                    break;

                case '^':
                    var    t     = value.Split(' ');
                    int    index = Int32.Parse(t[0]);
                    String item  = t[1];
                    array.Insert(index, item);
                    break;

                default:
                    break;
                }
            }
            int lenght = array.Count;
            var result = new String[lenght];

            for (int i = 0; i < lenght; i++)
            {
                result[i] = array[i];
            }
            return(result);
        }