当前位置: 首页>>代码示例>>C++>>正文


C++ PrintArray函数代码示例

本文整理汇总了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;
}
开发者ID:peterocean,项目名称:datastructure_algorithmanalysis,代码行数:32,代码来源:sort_test.c

示例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);
}
开发者ID:jColeChanged,项目名称:Exploration,代码行数:8,代码来源:main.cpp

示例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;
}
开发者ID:LucasYang7,项目名称:Sort-Algorithm,代码行数:9,代码来源:main.cpp

示例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;
}
开发者ID:retroburst,项目名称:Algorithms,代码行数:10,代码来源:main.c

示例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;
}
开发者ID:tangchn,项目名称:data_structure,代码行数:10,代码来源:BinaryInsertionSort.c

示例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 ;
}
开发者ID:ernestzhang,项目名称:edb,代码行数:55,代码来源:merge.c

示例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();
}
开发者ID:trankimhieu,项目名称:CTDL-TT,代码行数:11,代码来源:BinaryInsertionSort.cpp

示例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;
}
开发者ID:kelleyrw,项目名称:BuddTutorial,代码行数:11,代码来源:bubble_sort.cpp

示例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();
}
开发者ID:trankimhieu,项目名称:KTLT,代码行数:12,代码来源:bai02.cpp

示例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;
}
开发者ID:nhlinhmisfit,项目名称:CandC-,代码行数:13,代码来源:BubbleSort.c

示例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();
}
开发者ID:trankimhieu,项目名称:CTDL-TT,代码行数:13,代码来源:Shell+Sort.cpp

示例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;
}
开发者ID:tangchn,项目名称:data_structure,代码行数:49,代码来源:BubbleSort.c

示例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 );
}
开发者ID:ThereIsNoEscape,项目名称:uidaho,代码行数:15,代码来源:selSort.cpp

示例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;
}
开发者ID:ThereIsNoEscape,项目名称:uidaho,代码行数:26,代码来源:selSort.cpp

示例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);
}
开发者ID:Yuwain,项目名称:School,代码行数:38,代码来源:Lab4b.c


注:本文中的PrintArray函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。