Study : Quick Sort

C# 2020. 10. 26. 22:56

<퀵 정렬>

  :: 간략 정보

    - 가장 빠른 정렬 알고리즘

    - 자기 자신을 불러 쪼개서 정렬을 함

    - 수학적으로 이해해야 해서 더럽게 어려움

  :: 구조

    - 완벽하게 이해 못해서 못쓰겠음

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Study33_QuickSort
{
    public class App
    {
        public App()
        {
            // :: Testing Value
            int[] arr = new int[10] { 4, 8, 7, 6, 9, 1, 3, 2, 0, 5 };
            this.ShowArray(arr);

            this.QuickSort(arr, 0, arr.Length - 1);

            this.ShowArray(arr);

        }

        public void QuickSort(int[] arr, int indexStart, int indexEnd)
        {
            // :: Null Break;
            if (indexStart >= arr.Length)
                return;

            int target = arr[indexStart];
            int left = indexStart + 1;
            int right = indexEnd;

            while(left <= right)
            {
                // :: When target is bigger than Left Value : Skip
                while(arr[left] < target)
                {
                    left += 1;

                    // :: Null Break;
                    if (left >= arr.Length)
                        break;
                }
                // :: When target is smaller than Right Value : Skip
                while (arr[right] > target)
                {
                    right -= 1;

                    // :: Null Break;
                    if (right < 0)
                        break;
                }

                // :: I didn't understand this yet.
                if(left <= right)
                {
                    SwapArray(arr, left, right);
                }
            }            

            // :: I didn't understand this yet.
            // :: Until Start index is same End index : It means dividing is one now.
            if(indexStart < indexEnd)
            {
                // :: Swap target and Right Value
                SwapArray(arr, indexStart, right);

                QuickSort(arr, indexStart, right - 1); // :: Front
                QuickSort(arr, right + 1, indexEnd); // :: End
            }

            return;
        }

        public void SwapArray(int[] arr, int a, int b)
        {
            int temp = arr[a];
            arr[a] = arr[b];
            arr[b] = temp;
        }

        public void ShowArray(int[] arr)
        {
            foreach(var itm in arr)
            {
                Console.Write("[{0}]", itm);
            }
            Console.WriteLine("");
        }

        public void Today()
        {
            DateTime today = new DateTime(2020, 10, 26);
            Console.WriteLine(today.ToString("yyyy-MM-dd") + " : THINK");
        }
    }
}

 

글 업데이트 : 2020-10-26

 

참고 사이트 :

blockdmask.tistory.com/177

블로그 이미지

RIsN

,

【キャンバス】

・他のシーンにキャンバス丸ごと複製するとタッチが動かない。

⇒キャンバスは各シーンの自体のものを使おう。

【アニメーション】

・アニメーション(Damage)が終了するまで同じアニメーション(Damage)が動かない時の方法。

⇒!Animation.Rewind()!//初期化

// :: Animation Reset 
target.GetComponent<Animation>().Rewind(); 
// :: Hit Animation target.transform.LookAt(this.transform); 
target.GetComponent<Animation>().Play("damage");

【ビルド問題】

・JSONを読む時に避けるべきの文法

File.ReadAllText({filePath})

:Androidにビルドするとファイルの位置が変更されるので、JSONファイルなどを読めない場合がある。

 

⇒!こちらを使おう!

Resources.Load<TextAsset>({filePath})

:参考サイト:docs.unity3d.com/ScriptReference/Resources.Load.html

 

Unity - Scripting API: Resources.Load

If an asset can be found at path, it is returned with type T, otherwise returns null. If the file at path is of a type that cannot be converted to T, also returns null. The path is relative to any folder named Resources inside the Assets folder of your pro

docs.unity3d.com

:まだ意味は完全に理解していないが、こちらはAndroidビルドをしても関係なく動いた!

블로그 이미지

RIsN

,

변환 {0} => {0:#,0}

Console.WriteLine("{0:#,0}cc, {1}km/l", cc, kmLitre);

 

www.atmarkit.co.jp/ait/articles/0707/19/news143.html

'C#' 카테고리의 다른 글

백준 10828 : 스택 // 실패  (0) 2020.11.04
백준 4949: 균형잡힌 세상 // 성공  (0) 2020.11.01
백준 9012 : 괄호 // 성공  (0) 2020.10.31
백준 10773 : 제로 // 성공  (0) 2020.10.30
Study : Quick Sort  (0) 2020.10.26
블로그 이미지

RIsN

,