1 개요[ | ]
- C# 빗질정렬 구현
- C샵 빗질정렬 구현
C#
Copy
using System;
class Program {
static void combSort(int[] a) {
int i, temp, gap, size;
gap = size = a.Length;
bool swapped = true;
while( gap!=1 || swapped ) {
gap = gap*10/13;
if( gap<1 ) gap=1;
swapped = false;
for( i=0; i<size-gap; i++ ) {
if( a[i] > a[i+gap] ) {
temp=a[i]; a[i]=a[i+gap]; a[i+gap]=temp;
swapped = true;
}
}
}
}
static void Main() {
int[] arr = {9,1,22,4,0,-1,1,22,100,10};
combSort( arr );
Console.Write(string.Join(",",arr));
// -1,0,1,1,4,9,10,22,22,100
}
}
2 같이 보기[ | ]
편집자 Jmnote Jmnote bot
로그인하시면 댓글을 쓸 수 있습니다.