1. Bubble Sort
- 기초 정렬 알고리즘으로 오른쪽으로 한칸씩 이동하면서 두개 중 큰 값을 오른쪽으로 밀어내는 알고리즘

void bubbleSort(int** arrayData) { // cur번째 row에 말을 배치할 예정임
	int size = _msize(*arrayData) / sizeof(int);	
	for (int fixedIdx = 1; fixedIdx < size; fixedIdx++)
	{
		for (int idx = 0; idx < size - fixedIdx; idx++)
		{
			if ((*arrayData)[idx] > (*arrayData)[idx + 1])
			{
				int tmp = (*arrayData)[idx];
				(*arrayData)[idx] = (*arrayData)[idx + 1];
				(*arrayData)[idx + 1] = tmp;
			}
		}
	}	
}
int main(void) {
	int n = 0;
	cin >> n;
	int* arrayData = (int*)malloc(sizeof(int) * n);
	for (int idx = 0; idx < n; idx++)
	{
		cin >> arrayData[idx];
	}
	bubbleSort(&arrayData);
	for (int idx = 0; idx < n; idx++)
	{
		cout << arrayData[idx] << " ";
	}
	return 0;
}
'서버개발자 역량 > 알고리즘' 카테고리의 다른 글
| 알고리즘 ] 정렬(Merge Sort) (0) | 2020.01.03 | 
|---|---|
| 생각 ] 동시작업 서버 설계 (0) | 2019.12.19 | 
| 알고리즘 ] BFS 알고리즘 (백준 1926 - 그림 문제) (0) | 2019.12.12 | 
| 알고리즘 ] 백준 10799번 - 쇠막대기 (0) | 2019.12.10 | 
| 알고리즘 ] 백준 9012번 - 괄호 (0) | 2019.12.09 |