#include "Csort.h"
void cSort::_init()
{
Sort.Count = 0;
Sort.UpDown = 0;
cout << "입력 배열 개수 : ";
cin >> Sort.Count;
Sort.Num = (int *)malloc(sizeof(int)*Sort.Count);
int i = 0;
while(i < Sort.Count)
{
printf("%d 번째 숫자 : ", i + 1);
scanf("%d", &Sort.Num[i]); //num + loop);
i++;
}
}
void cSort::_sort()
{
cout << "[오름 차순 : 1] [내림차순 : 2] : ";
cin >> Sort.UpDown;
switch(Sort.UpDown)
{
case 1:
for(int x = 0; x < Sort.Count - 1 ; x++)
for(int y = x + 1 ; y < Sort.Count ; y++)
if(Sort.Num[x] > Sort.Num[y])
_swap(&Sort.Num[x], &Sort.Num[y]);
break;
case 2:
for(int x = 0; x < Sort.Count - 1 ; x++)
for(int y = x + 1 ; y < Sort.Count ; y++)
if(Sort.Num[x] < Sort.Num[y])
_swap(&Sort.Num[x], &Sort.Num[y]);
break;
}
}
void cSort::_swap(int *n1, int *n2)
{
int temp = *n1;
*n1 = *n2;
*n2 = temp;
}
void cSort::_print()
{
for(int i = 0 ; i < Sort.Count ; i++)
printf("%d\n", Sort.Num[i]);
free(Sort.Num);
}
'C.O.M.P.U.T.E.R > C.+.+' 카테고리의 다른 글
[0] |Objective-C| 숫자정렬 프로그램 .h 파일 (1/2) (0) | 2011.08.27 |
---|---|
[0] |C++| 숫자정렬 프로그램 .h 파일 (1/2) (0) | 2011.08.24 |
[0] |C++| 숫자야구게임 프로그램 .cpp 파일 (2/2) (0) | 2011.08.24 |