메뉴 건너뛰기

app

[MFC] Cptrarray 클래스를 이용한 정렬 프로그램

박영식2007.04.07 18:43조회 수 7907댓글 0

  • 1
    • 글자 크기
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
        int nRetCode = 0;

        // initialize MFC and print and error on failure
        if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
        {
                // TODO: change error code to suit your needs
                cerr << _T("Fatal Error: MFC initialization failed") << endl;
                nRetCode = 1;
        }
        else
        {
                // TODO: code your application's behavior here.
        int array_size, data_size, index_n, loop_n, order_v;  // 변수 선언
        srand( time(NULL) );  // rand()사용 준비
        CPtrArray m_ptrArray;  // 객체생성!
        int *inData = NULL; // 포인터 생성!

        array_size = 7;  // 배열의 수 지정
        data_size = 4;   // 데이터 공간 지정

        order_v = array_size-1; //순서대로 출력하기 위한 변수 선언 및 지정
        while(array_size--){
                inData = new int[data_size]; // data공간을 지정
                *inData = time(NULL)/rand()/rand(); // rand()으로 숫자 생성
                m_ptrArray.Add(inData); // prtArray에 저장
        }
        array_size = m_ptrArray.GetSize(); // 배열에 저장된 개수를 찾아냄
        int *outData = NULL; // 출력할 포인터 생성
        cout << "n 내용 : Cptrarray 클래스을 이용한 정렬 프로그램 n" ;
        cout << "n 임의의 배열 입력값 출력 n" ;
        while(array_size--){ // 저장된 개수 만큼 출력
                outData = new int[data_size]; // data공간을 지정
                outData = (int *)m_ptrArray.GetAt(order_v-array_size);
                        cout << order_v-array_size << "번째 = " << *outData << "n" ;
        }
        array_size = m_ptrArray.GetSize(); // 배열에 저장된 개수를 찾아냄
        loop_n = 0;
        index_n = 1;
        while(array_size--&&loop_n+index_n<=order_v){
                if(*(int *)m_ptrArray.GetAt(loop_n)<*(int *)m_ptrArray.GetAt(loop_n+index_n)){ //비교하기
                        m_ptrArray.InsertAt(loop_n, m_ptrArray.GetAt(loop_n+index_n)); // 기준 ptr배열에 삽입
                        m_ptrArray.RemoveAt(loop_n+index_n+1); // 배열의 순서가 한 칸씩 밀렸으므로 다음 배열이 옮겨진
                }                                                                                   // 위치에 있으므로 그 부분 삭제
                        index_n++;
                        if(loop_n+index_n>order_v&&loop_n<order_v){
                        loop_n++;
                        index_n = 1;
                        array_size = m_ptrArray.GetSize(); // 배열에 저장된 개수를 찾아냄
                }
//////////////////////정렬 과정을 보는 코드////////////////////////////
/*
                                cout << "n 정렬 과정 보기 n" ;
        array_size = m_ptrArray.GetSize(); // 배열에 저장된 개수를 찾아냄
        while(array_size--){ // 저장된 개수 만큼 출력
                outData = new int[4];  // data공간을 지정
                outData = (int *)m_ptrArray.GetAt(order_v-array_size);
                        cout << order_v-array_size << " = " << *outData << "n" ;
        }
*/
//////////////////////정렬 과정을 보는 코드/////////////////////////////////        
        }
                        cout << "n 정렬된 출력 n" ;
        array_size = m_ptrArray.GetSize(); // 배열에 저장된 개수를 찾아냄
        while(array_size--){ // 저장된 개수 만큼 출력
                outData = new int[data_size];  // data공간을 지정
                outData = (int *)m_ptrArray.GetAt(order_v-array_size);
                        cout << order_v-array_size << "번째 = " << *outData << "n" ;
        }
}

        return nRetCode;
}

박영식 (비회원)
  • 1
    • 글자 크기
[xcode] 스크롤뷰 사용하기 (by 박영식) [PHP] TM, WGS 좌표변환 (by 박영식)

댓글 달기

박영식
2003.11.05 조회 17486
박영식
2008.07.23 조회 7764
suritam9
2013.08.23 조회 7110
lispro06
2016.11.01 조회 7083
이전 1 2 3 4 5 6 7 8 9 10... 14다음
첨부 (1)
sort.JPG
34.6KB / Download 417
위로