コード例 #1
0
    IEnumerator bucketSort(Barobj[] array)
    {
        int range = cloneCount + 1;

        Barobj[] buckets = new Barobj[array.Length];

        for (int i = 0; i < array.Length; i++)
        {
            buckets[array.Length - array[i].height] = array[i];
            array[i].script.refresh(array.Length - array[i].height);
            yield return(null);
        }

        int j = 0;

        for (int i = array.Length - 1; i >= 0; i--)
        {
            if (0 < buckets[i].height)
            {
                array[j] = buckets[i];
                for (int l = 0; l <= i; l++)
                {
                    buckets[l].script.refresh(l + array.Length - 1 - i);
                }
                array[j].script.refresh(j);
                j++;
                yield return(null);
            }
        }
    }
コード例 #2
0
ファイル: SortManager.cs プロジェクト: Yukito-F/VisibleSort
    public void init()
    {
        barArray   = new Barobj[cloneCount];
        lengthList = new List <int>();
        for (int i = 0; i < cloneCount; i++)
        {
            lengthList.Add(i + 1);
        }

        for (int i = 0; i < cloneCount; i++)
        {
            var obj = Instantiate(bar, new Vector3(i, 0, 0), new Quaternion(), transform);
            index = UnityEngine.Random.Range(0, lengthList.Count);
            obj.transform.localScale = new Vector3(1, lengthList[index], 1);
            barArray[i] = new Barobj(lengthList[index], obj.GetComponent <Bar>());
            lengthList.RemoveAt(index);
        }
    }