본문 바로가기
C++ 알고리즘/5. 정렬 알고리즘

버블 정렬 (시간복잡도 O(N^2) ) -가장 비효율적

by Beijing_KingGod 2019. 9. 1.

 

#include <iostream>

using namespace std;

int main(){

	int array[] = {1,10,5,8,7,6,4,3,2,9};
	for(int i=0; i<sizeof(array)/sizeof(int); i++){
		for(int j=0; j<(sizeof(array)/sizeof(int))-1-i; j++){
			if(array[j]<array[j+1]){
				int temp=array[j+1];
				array[j+1]=array[j];
				array[j]=temp;
			}
		}
	}

	for(int i=0; i<sizeof(array)/sizeof(int); i++){
		cout<<array[i]<<" ";
	}
	cout<<endl;
	system("pause");
	return 0;
}
10 9 8 7 6 5 4 3 2 1

 

출처 :https://gmlwjd9405.github.io/2018/05/06/algorithm-bubble-sort.html

 

[알고리즘] 버블 정렬(bubble sort)이란 - Heee's Development Blog

Step by step goes a long way.

gmlwjd9405.github.io

출처:http://blog.naver.com/PostView.nhn?blogId=ndb796&logNo=221226803544&parentCategoryNo=&categoryNo=128&viewDate=&isShowPopularPosts=false&from=postList

댓글