c언어관련. 정열이 안되넹...도와주세요..
반혈
&&문제&&
1. 1부터 100까지 숫자를 임의의 순서로 배열에 저장 : random() 이용
2. 위의 배열을 삽입정렬하는데 소요되는 시간 측정 : time() 이용
3. 2번의 정렬 방법을 퀵정렬로 바꾸어 시간 측정
4. 3번의 퀵정렬을 C함수의 qsort() 이용하여 시간 측정
#include stdio.h
#include stdlib.h
#include time.h
#define SWAP(x,y,t) ((t)=(x),(x)=(y),(y)=(t))
void insertion_sort(int list[],int n) //삽입정렬
{
int i,j,key;
for(i=1;in;i++){
key = list[i];
for(j=i-1;j0 && list[j]key;j--)
list[j+1]=list[j];
list[j+1]=key;
}
}int partition(int list[],int left,int right) //퀵정렬
{
int pivot,temp;
int low,high;
low=left;
high=right+1;
pivot=list[left];
do{
do
low++;
while(list[low]pivot);
do
high--;
while(list[high]pivot);
if(lowhigh) SWAP(list[low],list[high],temp);
}while(lowhigh);
SWAP(list[left],list[high],temp);
return high;
}
int compare( const void *arg1, const *arg2) //qsort()
{
if(*(int *)arg1 *(int *)arg2) return 1;
else if(*(int *)arg1==*(int *)arg2) return 0;
else return -1;
}void main(){ //숫자100을 랜덤함수를 사용하여 중복없이 저장하는 함수
int arry[100];
int i, j, k;
srand((unsigned)time(NULL));
for(i=0;i100;i++)
{
arry[i]=rand()%100+1;
for(j=0; ji; j++){
if(arry[j]==arry[i]){
i--;
}
}
}
for(k=0; k100; k++)
printf(%d\n\n, arry[k]);
}//for(i=0; i100; i++){ 중복이 안되었는지 검사하는 함수
//for(j=0; ji; j++){
//if(arry[i] arry[j]){
//tmp = arry[i];
//arry[i] = arry[j];
//arry[j] = tmp;
//}
//}
//}
여기까지 짯는뎅..
도저히 진도가 나가지 않아요...워낙 초보자라서..ㅡ.ㅡ
함수만 만들었는데..에겅..
전문가님덜 도와주시면 안될까요...
부탁드립니당..꾸벅(--)(__)