Beispiel #1
0
        // The indexing will be consistent due to horizontal layout
        // index : data index in the tuple
        private void Sort(int index)
        {
            AbstractBinaryTree <ObjectTuple> heap;

            ObjectTuple[] tuples = TupleContainer.GetComponentsInChildren <ObjectTuple>();
            int Comparer(ObjectTuple a, ObjectTuple b)
            {
                return(string.Compare(a.Data[index].text, b.Data[index].text));
            }

            if (Order[index] == SortOrder.Ascending)
            {
                heap         = new MinHeap <ObjectTuple>(Comparer);
                Order[index] = SortOrder.Descending;
            }
            else
            {
                heap         = new MaxHeap <ObjectTuple>(Comparer);
                Order[index] = SortOrder.Ascending;
            }

            for (int i = 0; i < tuples.Length; i++)
            {
                heap.Add(tuples[i]);
            }

            int n = 0;

            while (!heap.IsEmpty())
            {
                heap.Remove().transform.SetSiblingIndex(n++);
            }
        }
        // The indexing will be consistent due to horizontal layout
        // index : data index in the tuple
        private void Sort(int index)
        {
            var tuples = TupleContainer.GetComponentsInChildren <ObjectTuple>().ToList();

            int Comparer(ObjectTuple a, ObjectTuple b)
            {
                return(string.Compare(a.Data[index].text, b.Data[index].text));
            }

            tuples.Sort(Comparer);

            for (int i = 0; i < tuples.Count; i++)
            {
                tuples[i].transform.SetSiblingIndex(i);
            }
        }