MergeSort(합병정렬), C, C++
데이터를 각각 낱개로 나눈 후 합치면서 정렬하는 알고리즘으로 속도면에서 빠르다. 주석은 내가 이해한대로, 해석한대로 달아보았고 추후에 이미지 설명이나 등등을 추가해볼 계획이다. #include #define MAX 6 void mergesort_divide(int*, int, int); void mergesort_conquer(int*, int, int, int); void mergesort_conqure(int a[], int start, int end, int mid_index){ //any array int b[1000]; //first index of left array int i = start; //first index of right array int j = mid_index + 1; //so..
2020. 1. 14.
InsertionSort(삽입정렬), C, C++
※테스트 환경은 Dev C++에서 하였고 첨부파일도 Dev C++에서 만든 소스파일입니다. 회전마다 비교하는 데이터의 갯수를 점점 증가시킨다. 정렬이 거의 다 되어 있는 경우 가장 빠르다. ( 예, 1회전 - 2개 데이터 비교, 2회전 - 3개 데이터비교....) //정렬이 거의 다 되어 있는 경우 버블, 삽입, 선택 중 가장 빠르다. #include int main(){ int a[] = {50, 20, 30, 10, 40}; int size = sizeof(a)/sizeof(int); int temp, j; for(int i = 0; i < size; i++){ printf("%d ", a[i]); } for(int i = 1; i < size; i++){ j = i; while(j != 0){ if..
2020. 1. 13.