本文整理汇总了C++中PrintArray函数的典型用法代码示例。如果您正苦于以下问题:C++ PrintArray函数的具体用法?C++ PrintArray怎么用?C++ PrintArray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PrintArray函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
int N = 0;
ElementType *A;
if (argc != 2) return -1;
N = atoi(argv[1]);
assert(N != 0);
A = malloc(sizeof(ElementType)*N);
assert(A != NULL);
memset(A,0,N*sizeof(ElementType));
RandomFillArray(A,N);
printf("original array:\n");
PrintArray(A,N);
printf("sort start:\n");
// InsertSort(A,N);
// BubbleSort(A,N);
// ShellSort_V2(A,N);
// QuickSort(A,N);
MergeSort(A,N);
printf("sort end.\n");
printf("After sort array is:\n");
PrintArray(A,N);
free(A);
return 0;
}
示例2: RunQuickSort
void RunQuickSort(void)
{
int to_partition[] = {2, 1, 3, 7, 1, 3, 6, 4, 8, 3, 4, 1};
int size = sizeof(to_partition) / sizeof(int);
PrintArray(to_partition, size);
Quicksort(to_partition, 0, size);
PrintArray(to_partition, size);
}
示例3: main
int main()
{
int array[] = {10,9,8,7,6,5,4,3,2,1};
int len = sizeof(array) / sizeof(int);
PrintArray(array,len,"直接插入排序前:");
InsertSort(array,len);
PrintArray(array,len,"直接插入排序后:");
return 0;
}
示例4: main
// main - entry point
int main(int argc, const char * argv[]) {
int numbers[10] = { 12, 445, 55, 67, 2, 7, 909, 45, 4454, 1 };
printf("Before Insertion Sort: ");
PrintArray(numbers, 10);
InsertionSort(numbers, 10);
printf("After Insertion Sort: ");
PrintArray(numbers, 10);
return 0;
}
示例5: main
int main(void)
{
ElemType* const array = (ElemType*)malloc(sizeof(ElemType)*ARRAY_NUMBER );
InitalArray(array);
PrintArray(array);
BinaryInsertionSort(array,ARRAY_NUMBER );
printf("排序结果为:");
PrintArray(array);
return 0;
}
示例6: main
int main()
{
#if 0
int i;
int iPos = 0 ;
int iArr1[]={1,7 , 12 ,15,16,17,19,22,23 , 26};
int iSize = sizeof(iArr1)/sizeof(iArr1[0]) ;
void **pAddr = malloc( iSize * sizeof(void *));
for(i = 0 ; i < iSize ; ++i)
{
pAddr[i] = iArr1 + i ;
}
PrintArray(iArr1 , iSize , &i);
while(i != -1)
{
int iRet = BSearch( pAddr , sizeof(iArr1)/sizeof(iArr1[0]) , (void *)&i , CompareFunc ,&iPos);
if(iRet == 0)
{
printf("bingo ! pos:%d\n" , iPos);
}
else
{
printf("bad luck ! pos:%d\n" , iPos);
}
PrintArray(iArr1 , iSize , &i);
}
#endif
int i ;
int iArr1[] = { 24 , 25};
int iArr2[]={1,2,3,4,5 , 8 , 9 , 23 };
unsigned int iSize1 = sizeof(iArr1)/sizeof(iArr1[0]) ;
unsigned int iSize2 = sizeof(iArr2)/sizeof(iArr2[0]) ;
void **p1 = malloc(iSize1 * sizeof(void *));
void **p2 = malloc(iSize2 * sizeof(void *));
void **pMerge = (void **)malloc( sizeof(void *)* (iSize1 + iSize2));
for(i = 0 ; i < iSize1 ; ++i)
{
p1[i] = iArr1 + i ;
}
for(i = 0 ; i < iSize2 ; ++i)
{
p2[i] = iArr2 + i ;
}
for(i = 0 ; i < (iSize1 + iSize2) ; ++i)
{
pMerge[i] = NULL ;
}
Merge(p1 , iSize1 , p2 , iSize2 ,CompareFunc , pMerge);
for(i = 0 ; i < (iSize1 + iSize2) ; ++i)
{
printf("%d " , *((int *)pMerge[i]));
}
printf("\n");
return 0 ;
}
示例7: main
void main()
{
int a[100];
int n;
RandomArray(a,n);
PrintArray(a,n);
//SimpleSort(a,n);
BinaryInsertionSort(a,n);
PrintArray(a,n);
getch();
}
示例8: main
int main()
{
// data
int values[] = {32,71,12,45,26,80,53,33};
const unsigned int n = sizeof(values)/sizeof(values[0]);
std::cout << "value before ="; PrintArray(values, n);
BubbleSort(values, n);
std::cout << "value after ="; PrintArray(values, n);
return 0;
}
示例9: main
void main()
{
int a[100];
int b[100];
int n;
int m = 0;
RandomArray(a,n);
CreateNewArray(a,b,n,m);
PrintArray(a,n);
PrintArray(b,m);
getch();
}
示例10: main2
int main2(void){
int aScores[20]={0};
int els = numsof(aScores);
int i;
srand((unsigned int)time(NULL));
RandomArray(aScores);
PrintArray(aScores);
BubbleSort(aScores, els);
PrintArray(aScores);
return 0;
}
示例11: main
void main()
{
int a[100];
int h[100];
int n,k;
RandomArray(a,n);
PrintArray(a,n);
GetSteps(h,k,n);
ShellSort(a,n,h,k);
PrintArray(a,n);
getch();
}
示例12: main
int main(void)
{
int i;
u64 begin,end;
ElemType* const array = (int*)malloc(sizeof(int)*ARRAY_NUMBER );
InitalArray(array);
PrintArray(array);
ElemType* tempArray1 = (int*)malloc(sizeof(int)*ARRAY_NUMBER );
ElemType* tempArray2 = (int*)malloc(sizeof(int)*ARRAY_NUMBER );
ElemType* tempArray3 = (int*)malloc(sizeof(int)*ARRAY_NUMBER );
for(i = 0; i < ARRAY_NUMBER ; i++)
{
tempArray1[i] = array[i];
tempArray2[i] = array[i];
tempArray3[i] = array[i];
}
//冒泡排序
Rdtsc(&begin);
BubbleSort(array);
Rdtsc(&end);
printf("冒泡排序后的数组是:");
PrintArray(array);
printf("花费时间为:%llu \n",end - begin);
Rdtsc(&begin);
BubbleSort2(tempArray1);
Rdtsc(&end);
printf("冒泡排序2后的数组是:");
PrintArray(tempArray1);
printf("花费时间为:%llu \n",end - begin);
Rdtsc(&begin);
BubbleSort3(tempArray2);
Rdtsc(&end);
printf("冒泡排序3后的数组是:");
PrintArray(tempArray2);
printf("花费时间为:%llu \n",end - begin);
Rdtsc(&begin);
BubbleSort4(tempArray3);
Rdtsc(&end);
printf("冒泡排序4后的数组是:");
PrintArray(tempArray3);
printf("花费时间为:%llu \n",end - begin);
return 0;
}
示例13: main
int main()
{
aType testArray[] = { 7, 13, 1, 3, 10, 5, 2, 4 };
int nA = sizeof(testArray)/sizeof(aType);
cout << "nA: " << nA << endl;
cout << "Initial array contents:" << endl;
PrintArray( testArray, nA );
SelectionSort( testArray, nA );
cout << "Final array contents:" << endl;
PrintArray( testArray, nA );
}
示例14: SelectionSort
void SelectionSort( aType A[], int nElements )
{
int iSmallest;
aType tmp;
cout << "------------------------" << endl;
cout << "In SelectionSort():" << endl;
for( int i = 0 ; i < nElements ; i++ )
{
cout << " Pass: " << i << endl;
iSmallest = IndexOfSmallest( A, i, nElements-1 );
// swap
if( iSmallest > i )
{
tmp = A[i];
A[i] = A[iSmallest];
A[iSmallest] = tmp;
}
PrintArray( A, nElements );
}
cout << "SelectionSort() finished" << endl;
cout << "------------------------" << endl;
}
示例15: BubbleSort
//Function sorts pointer array according to input order
//Input: pointer array, size of array, sort order
//Output: pointer array sorted by sort order
void BubbleSort(int *array, int size, int order)
{
int a;
int loop = 1;
while (loop)
{
loop = 0;
for (a = 0; a < size-1; a++)
{
//Sorts array in ascending order
if (order == 1)
if (*array > *(array+1))
{
Swap(array, array+1);
loop = 1;
}
//Sorts array in decending order
if (order == -1)
if (*array < *(array+1))
{
Swap(array, array+1);
loop = 1;
}
array++;
}
array = array - (size - 1);
}
PrintArray(array, 20);
}