1.버블 소트
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char * argv[])
{
int inputCase;
int *arr;
int i,j,k,l;
int temp = 0;
scanf("%d",&inputCase);
arr=(int*) malloc(sizeof(int) * inputCase);
for(i=0; i<inputCase; i++)
{
scanf("%d",arr+i); //arr[i] 는 안됨. why?
}
/*bubble sort*/
for(j=0; j<inputCase; j++)
{
for(l=0; l<inputCase-1; l++)
{
if(arr[l] > arr[l+1])
{
temp = arr[l];
arr[l] = arr[l+1];
arr[l+1] = temp;
}
}
}
for(k=0; k<inputCase; k++)
{
printf("%d\n",arr[k]);
}
free(arr);
return 0;
}
사진,문제 출처 - https://www.acmicpc.net/problem/2750
'Computer Science > Algorithm' 카테고리의 다른 글
[Algorithm/C] Project Euler. Multiple of 3 and 5 (0) | 2017.11.27 |
---|---|
알고리즘 문제 풀이 사이트 (0) | 2017.11.27 |
[Algorithm/C] BOJ.1011 Fly me to the Alpha Centauri (0) | 2017.11.24 |
[Algorithm/C] BOJ.2438 별찍기 (0) | 2017.11.23 |
[Algorithm/C] BOJ.2775 부녀회장 (2) | 2017.11.22 |