목차
없음
본문내용
t * const, int * const );
int main()
{
const int arraySize = 10;
int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
cout << "Data items in original order\n";
for( int i = 0; i < arraySize; i++ )
cout << setw( 4 ) << a[ i ];
/* “bubbleSort" 함수를 호출하여 배열 (array) “a"를 정렬 (sort) 한다. 함수 호출 (function call)을 쓰시오 */
bubbleSort( a, arraySize );
cout << "\nData items in ascending order\n";
for( int j = 0; j < arraySize; j++ )
cout << setw( 4 ) << a[ j ];
return 0;
}
// sort an array of integers using bubble sort algorithm
void bubbleSort( int *array, const int size )
{
// loop to control passes
for ( int pass = 0; pass < size - 1; pass++ )
{
// loop to control comparisons during each pass
for ( int k = 0; k < size - 1; k++ )
{
/* 다음의 조건이 참 (true)일 경우 배열 (array)의 두 엘리멘트 (element)를 교환 (swaping)하는 함수 "swap"을 function declaration (prototype)과 주어진 상황에 맞게 호출하시오. */
if ( array[ k ] > array[ k + 1 ] )
{
swap( &array[ k ], &array[ k + 1 ] );
}
}
}
}
/* 두 엘리멘트를 function declaration (prototype)과 주어진 상황에 맞게 입력 받아 교환하는 함수 “swap”의 definition을 작성하시오. */
void swap( int * const element1Ptr, int * const element2Ptr )
{
int hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
int main()
{
const int arraySize = 10;
int a[ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 68, 45, 37 };
cout << "Data items in original order\n";
for( int i = 0; i < arraySize; i++ )
cout << setw( 4 ) << a[ i ];
/* “bubbleSort" 함수를 호출하여 배열 (array) “a"를 정렬 (sort) 한다. 함수 호출 (function call)을 쓰시오 */
bubbleSort( a, arraySize );
cout << "\nData items in ascending order\n";
for( int j = 0; j < arraySize; j++ )
cout << setw( 4 ) << a[ j ];
return 0;
}
// sort an array of integers using bubble sort algorithm
void bubbleSort( int *array, const int size )
{
// loop to control passes
for ( int pass = 0; pass < size - 1; pass++ )
{
// loop to control comparisons during each pass
for ( int k = 0; k < size - 1; k++ )
{
/* 다음의 조건이 참 (true)일 경우 배열 (array)의 두 엘리멘트 (element)를 교환 (swaping)하는 함수 "swap"을 function declaration (prototype)과 주어진 상황에 맞게 호출하시오. */
if ( array[ k ] > array[ k + 1 ] )
{
swap( &array[ k ], &array[ k + 1 ] );
}
}
}
}
/* 두 엘리멘트를 function declaration (prototype)과 주어진 상황에 맞게 입력 받아 교환하는 함수 “swap”의 definition을 작성하시오. */
void swap( int * const element1Ptr, int * const element2Ptr )
{
int hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
추천자료
객체지향 프로그래밍 (자바) 전체 수업 소스 및 리포트
객체지향 UML 모바일 문제기술서
객체지향프로그램_자판기프로그램
[사이버엠비에이]생산관리 중간고사
현대생활과패션 청주대 사이버 중간고사
(청주대)성공하는 프레젠테이션 (중간고사)
객체지향프로그래밍, c++
객체지향프로그래밍, c++ - 간단한 클래스 만들고 사용하기
객체지향프로그래밍, c++ - Report #4 : CString 클래스 만들기
아이스베리(Iceberry)의 브라질 진출전략 (중간고사 요약, 브라질 무역협정, 핵심역량, SWOT,...
행정조직론 요점정리 1(중간고사범위)
청주대학교 관광산업의 이해(중간고사) 2014년 최신판(1-7주)
원광대 숲과문화 강의노트1~15주차(2015 2학기), 1.2차 과제(2015 2학기), 중간.기말고사 문...
소개글