예제 #1
0
        static public void swap(MyArray arr, int a, int b)
        {
            int temp;

            temp       = arr.obj[a];
            arr.obj[a] = arr.obj[b];
            arr.obj[b] = temp;
        }
예제 #2
0
        static public int[] sort(MyArray arr)
        {
            int len = arr.obj.Length;

            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < len - i - 1; j++)
                {
                    if (arr.obj[j] > arr.obj[j + 1])
                    {
                        MyArray.swap(arr, j, j + 1);
                    }
                }
            }
            return(arr.obj);
        }
예제 #3
0
        static void Main(string[] args)
        {
            var algo = getAlgo();             //return int 1-5
            //var type = getDataType();//return int 1-3    benched this idea for now
            List <int> inputData = getData(); //returns a list of user input
            var        data      = inputData.ToArray();
            MyArray    arr       = new MyArray(data);

            switch (algo)
            {
            case "1":
                //create merge sort
                merge.input(arr);
                break;

            case "2":
                //create bubble sort
                bubble.sort(arr);
                break;

            case "3":
                //create quick sort
                //quick.sort(arr.obj);
                break;

            case "4":
                //create insertion sort
                //insertion.sort(arr.obj);
                break;

            case "5":
                //create heap sort
                //heap.sort(arr.obj);
                break;

            default:
                Console.WriteLine("how did you get here??");
                break;
            }

            Console.WriteLine("Original:");
            printList(inputData);
            Console.WriteLine("Sorted:");
            MyArray.print(arr.obj);
        }
예제 #4
0
 static public int[] input(MyArray arr)
 {
     mergeSort(arr.obj, 0, arr.obj.Length - 1);
     return(arr.obj);
 }