Ejemplo n.º 1
0
        public static line[] MergeSort(line[] array)
        {
            // If list size is 0 (empty) or 1, consider it sorted and return it
            // (using less than or equal prevents infinite recursion for a zero length array).
            if (array.Length <= 1)
            {
                return(array);
            }

            // Else list size is > 1, so split the list into two sublists.
            int middleIndex = (array.Length) / 2;

            line[] left  = new line[middleIndex];
            line[] right = new line[array.Length - middleIndex];

            Array.Copy(array, left, middleIndex);
            Array.Copy(array, middleIndex, right, 0, right.Length);

            // Recursively call MergeSort() to further split each sublist
            // until sublist size is 1.
            left  = MergeSort(left);
            right = MergeSort(right);

            // Merge the sublists returned from prior calls to MergeSort()
            // and return the resulting merged sublist.
            return(Merge(left, right));
        }
Ejemplo n.º 2
0
        static List <string> fromtrie(string s)
        {
            List <string> l  = new List <string>();
            List <line>   nl = new List <line>();
            string        temp;

            //list from trie with result of search
            l = t.GetCompletionList(s);
            List <string> result = new List <string>();
            int           size   = l.Count();

            line[] arr   = new line[size];
            line[] narry = new line[size];
            //fill the result into an arry
            for (int i = 0; i < size; i++)
            {
                temp = l[i];
                string[] fields = temp.Split(',');
                line     x      = new line(int.Parse(fields[1]), fields[0]);
                arr[i] = x;
            }
            narry = MergeSort(arr);
            for (int i = 0; i < size; i++)
            {
                result.Add(narry[i].s);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public static line[] performInsertionSort(line[] inputarray)
        {
            for (int i = 0; i < inputarray.Length - 1; i++)
            {
                int j = i + 1;

                while (j > 0)
                {
                    if (inputarray[j - 1].w > inputarray[j].w)
                    {
                        line temp = inputarray[j - 1];
                        inputarray[j - 1] = inputarray[j];
                        inputarray[j]     = temp;
                    }
                    j--;
                }
            }
            return(inputarray);
        }
Ejemplo n.º 4
0
        private void button2_Click(object sender, EventArgs e)
        {
            List <string> l  = new List <string>();
            List <line>   nl = new List <line>();
            string        temp;

            l = t.GetCompletionList(textBox1.Text);
            int size = l.Count();

            line[] arr   = new line[size];
            line[] narry = new line[size];
            for (int i = 0; i < size; i++)
            {
                temp = l[i];
                string[] fields = temp.Split(',');
                line     x      = new line(int.Parse(fields[1]), fields[0]);
                arr[i] = x;
            }
            narry = performInsertionSort(arr);
            dataGridView2.DataSource = narry;
        }