퀵 정렬은 찰스 앤터니 리처드 호어 라는 분이 1959년에 개발한 정렬 알고리즘입니다.

이름처럼 웬만한 상황에서는 빠른 알고리즘이고 많이 사용되고 있습니다.


최선 & 평균 시간복잡도는 

최악 시간복잡도는 

입니다.


퀵 소트가 동작하는 방법을 단순하게 표현한다면 다음과 같습니다. (오름차순 기준)


1. 가운데 값을 정한다 (기준점 4)

           

{2 3 1 6 4 8 5 7 9}


2. 값을 기준으로 작은건 왼쪽으로 큰건 오른쪽으로 보낸다.

        

{2 3 1 4 8 5 7 9}


3. 가운데 값을 기준으로 구역을 나누고 구역마다 다시 가운데 값을 정한다. (기준점 3,5)

   ▼             

{2 3 1} 4 {8 5 7 9}


4. 구역마다 1~ 3번을 다시 반복한다.

      ▼   

{2 1 3} 4 {5 6 8 7 9}


5. 또 다시 구역을 나눠서 나눌 구역이 없을 때 까지 반복한다...



위의 과정을 구현한 소스코드는 이런모양 (출처 : 위키백과)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void quickSort(int arr[], int left, int right)//정렬할 배열,구역의 왼쪽,구역의 오른쪽
{
      int i = left, j = right;//i=왼쪽 ,j=오른쪽
      int pivot = arr[(left + right) / 2];//기준점은 구역의 중간
      int temp;
      do 
      {
        while (arr[i] < pivot)//왼쪽이 피벗보다 (어차피)작다면 스킵
            i++;
        while (arr[j] > pivot)//오른쪽이 피벗보다 (어차피)크다면 스킵
            j--;
        if (i<= j)//위에서 걸러지지 못한건 서로 교체
        {
            temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
            i++;
            j--;
        }
      } while (i<= j);//왼쪽이랑 오른쪽이랑 만날때까지 반복
 
    /* 구역나눠 재귀 */
    if (left < j)//왼쪽 구역
        quickSort(arr, left, j);
 
    if (i < right)//오른쪽 구역
        quickSort(arr, i, right);
}
cs

이 소스코드가 위에 설명한거랑 조금 달라보일 수 있는데

조금 달라보여도 자세히 보면 위 설명과 크게 다르지는 않습니다.


저 소스를 더 분석하자면... 


1. 왼쪽(i) 오른쪽(j)과 가운데 값(피벗)이 있다.

 i          ▼         j

{2 3 1 6 4 8 5 7 9}


2. i, j가 피벗을 기준으로 제대로 된 위치에 있으면 스킵 

(이상황에서는 결국 j랑 피벗이랑 같은위치)

          i▼(j)

{2 3 1 6 4 8 5 7 9}


3. 제대로 된 위치가 아니면 i랑 j의 위치를 변경

{2 3 1 4 6 8 5 7 9}


4. 왼쪽부터 j까지 , i부터 오른쪽까지 구역나눠서 반복

{2 3 1 4} {6 8 5 7 9}



그리고 퀵소트의 원리를 보여주는 헝가리 민속 탭 떈쓰~ (겁나 흥겨움)


https://ko.wikipedia.org/wiki/%ED%80%B5_%EC%A0%95%EB%A0%AC

블로그 이미지

stuban

ㅇ.ㅇ

,

정확히는 마우스 포인터가 UI위에 있는지 확인하는 함수!


1
2
3
4
5
6
7
8
9
10
11
12
void Update()
{
    if (Input.GetMouseButtonUp(0)//클릭
    {
        //마우스 포인터가 UI위에 있지않으면
        if(UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject() == false)
        {
            ...
        }
    }
}
 
cs


블로그 이미지

stuban

ㅇ.ㅇ

,

https://blogs.unity3d.com/kr/2018/05/02/2018-1-is-now-available/



유니티 2018버전이 나왔다.


새로 추가된 기능으로는


Scriptable Render pipeline : 렌더링 파이프라인을 쉽게 수정할 수 있음 그리고 고사양 파이프라인이랑 저사양 파이프라인을 기본적으로 제공함 (AAA용 , 모바일용)

멀티코어 프로세서 활용 : 멀티코어 프로세서를 최대한 활용할 수 있음

레벨디자인 & 쉐이더 : 타임라인,시네머신 , 프로빌더 기본내장(FBX Exporter) , 새로운 쉐이더 에디터

패키지 : 패키지 관리자 인터페이스 추가


ps4 프로를 위한 동적 해상도

2D 리지드바디 시뮬레이션을 할때 모든 CPU의 코어를 사용할 수 있음

2D스프라이트 쉐이프 : 스프라이트를 휘거나 어떤 모양을 타일링 텍스쳐로 채우거나 하는 등의 기능

2D애니메이션 시스템 : 2D본 애니메이션


등이 있다.


블로그 이미지

stuban

ㅇ.ㅇ

,

텍스트에셋을 사용해서 텍스트파일을 불러오려는데 텍스트파일의 내용이 비어있었다.

처음에는 너무 양이 많아서 안불러오는거라고 생각했으나 (100줄정도 되는 분량)


약간의 삽질끝에 파일안에 있는 한글이 문제였다는 것을 깨닳게 되었다.


방법은 UTF-8로 인코딩하기



메모장에서 다른이름으로 저장할때 밑에있는 인코딩을 UTF-8로선택하면



인스펙터에서 안보이던 글이



다시 보이게 된다.




블로그 이미지

stuban

ㅇ.ㅇ

,
1
2
3
4
5
6
7
8
List<Test> result = new List<Test>();
 
//합치기
result.AddRange(list1);
result.AddRange(list2);
 
//중복 제거
result = result.Distinct().ToList();
cs



블로그 이미지

stuban

ㅇ.ㅇ

,


MotionEvent라는 클래스가 있다.

이 클래스에는 터치 관련된 상수들이 정의되어 있다.


이 중에서 여러 상수들이 정의돼 있지만 일단 내가 정확히 알고 있고 왠지 많이 쓰일 거 같은 거 3가지를 추려보자면...


ACTION_DOWN : 처음 눌렸을 때

ACTION_MOVE : 누르고 움직였을 때

ACTION_UP : 누른걸 땠을 때



MotionEvent를 사용할 수 있는 곳은


1. onTouchEvent


onTouchEvent는 화면을 터치하면 호출되는 콜백 메소드이다.

onTouchEvent는 인자로 MotionEvent를 가지고 있으니 매개변수에 getAction()메소드를 사용하여 MotionEvent 상수들과 비교하면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public boolean onTouchEvent(MotionEvent event) {
 
    switch (event.getAction())
    {
        case MotionEvent.ACTION_DOWN:
            textView.setText("ACTION_DOWN");
            return true;
 
        case MotionEvent.ACTION_MOVE:
            textView.setText("ACTION_MOVE");
            return true;
 
        case MotionEvent.ACTION_UP:
            textView.setText("ACTION_UP");
            return false;
    }
    return false;
}
cs



ACTION_DOWN과 ACTION_MOVE는 return true를 하고

ACTION_UP은 return false를 해야지 안전하다고 하는데 

return대신 break를 넣어도 나는 차이를 느낄 수 없었다.



2. 버튼의 리스너


버튼의 리스너로 등록가능하다.

onTouch에도 MotionEvent가 인자로 들어가니 1번 처럼 쓰면 된다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
button = (Button)findViewById(R.id.button);
 
button.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                textView.setText("ACTION_DOWN");
                return true;
 
            case MotionEvent.ACTION_MOVE:
                textView.setText("ACTION_MOVE");
                return true;
 
            case MotionEvent.ACTION_UP:
                textView.setText("ACTION_UP");
                return false;
        }
        return false;
    }
});
 
cs






다른 사용방법이 있거나 내가 틀린 부분이 있겠지만 아무튼 다른 내용은 구글 디벨로퍼를 참고하자

https://developer.android.com/reference/android/view/MotionEvent.html


블로그 이미지

stuban

ㅇ.ㅇ

,
우선 xml에 있는 위젯을 자바코드로 가지고 오는 방법


1
TextView widget = (TextView)findViewById(R.id.textview);

cs




저번에 올린 속성들을 자바코드에서 컨트롤하는 법


1
2
3
4
widget.setBackgroundColor(Color.RED); //배경색깔
widget.setVisibility(View.INVISIBLE); //보이기
widget.setClickable(false); //클릭활성화
widget.setRotation(44); //회전 
cs


보통 set 뒤에 바꾸고 싶은 속성을 시작을 대문자로 하여 조합하면 됨


1
android:rotation="44"
cs

  ↓

1
widget.setRotation(44);
cs


반대로 속성값을 가지고 오려면 get을 시작으로 두면 되는데

테스트는 안 해 봤으니깐 장담할 수는 없다.




레이아웃속성을 바꾸는 방법은 다른 것들을 바꾸는 것보다 조금더 복잡하다.


1
2
3
4
5
6
7
8
9
10
11
//레이아웃 파라미터를 만듬
//LayoutParams의 생성자는 너비, 높이 순서다 (물론 다른 생성자도 있음)
LinearLayout.LayoutParams lparam = 
    new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT);
 
//이렇게 따로 설정 할 수 있다.
lparam.width = ViewGroup.LayoutParams.WRAP_CONTENT;
lparam.height = ViewGroup.LayoutParams.MATCH_PARENT;
lparam.topMargin = 100;//픽셀 단위인듯
 
widget.setLayoutParams(lparam);//마지막에 setLayoutParams으로 넣어주면 끝
cs



https://developer.android.com/reference/android/widget/LinearLayout.LayoutParams.html

블로그 이미지

stuban

ㅇ.ㅇ

,

그림 출처는 한빛 아카데미에서 나온 Android Studio를 활용한 안드로이드 프로그래밍



뷰는 화면에 나오는 모든것들이 상속 받고 있는 클래스다.


버튼이나 텍스트같은 위젯은 물론이고 이것들을 정렬하는 레이아웃도 뷰를 상속하고 있다.




아래는 자주쓴다는 뷰의 속성들을 가지고 만든 예제 이다.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!--xml에서 주석은 이렇게 쓴다 하지만 내용 중간에(전문용어로는 애트리뷰트라고 하는 듯)쓰면 빨간줄이 쳐진다-->
<!--따라서 설명하고 싶은 부분은 괄호를 처서 설명할거임 '()' -->
 
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" (정렬방향을 정함 (기본은 가로방향))
    android:paddingTop="50dp" (안쪽에 위쪽으로 간격을  (위나 아래로 따로 주고 싶다면 뒤에 paddingTop paddingLeft등을 사용하면 됨))
    tools:context="com.stuban.test222.MainActivity">
 
 
    <TextView
        android:id="@+id/textview" (java코드에서 위젯을 찾기위한 id @+id/textView는 R파일의 id에 textView를 추가한다는 뜻)
        
        (위젯의 크기 match_parent는 부모의 사이즈에 맞추는 거고 wrap_content는 내용물의 크기에 맞추는 것)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        
        android:background="#FF0000" (배경색)
        
        android:text="test"
        />
 
    <!--visibility-->
 
    <TextView
        android:visibility="invisible" (안보임)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="invisible"
        />
 
    <TextView
        android:visibility="visible" (보임 (기본))
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="visible"
        />
 
    <TextView
        android:visibility="gone" (그냥 없는 취급)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="gone"
        />
 
    <!--enabled,clickable-->
 
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button"
        />
 
    <Button
        android:enabled="false"(버튼 사용 못함)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="!enabled"
        />
 
    <Button
        android:clickable="false" (터치 무시)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="!clickable"
        />
 
    <!--rotation-->
 
    <Button
        android:layout_marginTop="100dp"(바깠쪽에 간격을  (위나 아래로 따로 주고 싶다면 뒤에 marginTop marginLeft등을 사용하면 됨))
        android:rotation="44" (회전)
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Button" />
 
</LinearLayout>
cs



결과 



참고 : https://developer.android.com/reference/android/view/View.html

블로그 이미지

stuban

ㅇ.ㅇ

,