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


C++ BubbleSort函数代码示例

本文整理汇总了C++中BubbleSort函数的典型用法代码示例。如果您正苦于以下问题:C++ BubbleSort函数的具体用法?C++ BubbleSort怎么用?C++ BubbleSort使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了BubbleSort函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CompareQualifiers

PEGASUS_NAMESPACE_END

void CompareQualifiers(
    CIMRepository& r1,
    CIMRepository& r2,
    const CIMNamespaceName& namespaceName)
{
    Array<CIMQualifierDecl> quals1 = r1.enumerateQualifiers(namespaceName);
    Array<CIMQualifierDecl> quals2 = r2.enumerateQualifiers(namespaceName);
    PEGASUS_TEST_ASSERT(quals1.size() == quals2.size());

    BubbleSort(quals1);
    BubbleSort(quals2);

    for (Uint32 i = 0; i < quals2.size(); i++)
    {
        if (verbose)
        {
            cout << "testing qualifier " << namespaceName.getString() << "/";
            cout << quals1[i].getName().getString() << "/ against /";
            cout << quals2[i].getName().getString() << "/" << endl;
        }

        PEGASUS_TEST_ASSERT(quals1[i].identical(quals2[i]));
    }
}
开发者ID:brunolauze,项目名称:pegasus,代码行数:26,代码来源:CompareRepositories.cpp

示例2: main

int main()
{
	int num_array[NUM] = {0}; // Create our array
	int i = 0; // A counter for our for loops

	for(; i < NUM; i++)
		num_array[i] = rand()%1000; // Fill it with random numbers

	// Sort the array from least to greatest
	BubbleSort(num_array,NUM,true);

	// Print it out
	for(i = 0; i < NUM; i++)
		printf("%d ",num_array[i]);

	printf("\n\n"); // A couple blank lines

	// Sort the array from greast to least
	BubbleSort(num_array,NUM,false);

	// Print it out
	for(i = 0; i < NUM; i++)
		printf("%d ",num_array[i]);

	printf("\n\n"); // A couple blank lines

	return 0; // And we're done
}
开发者ID:twinklingstar20,项目名称:Programming-Tutorials,代码行数:28,代码来源:main.c

示例3: Set_Union

int Set_Union() {
  /* Get length of arrays */
  int lenA = arr_size(SetA);
  int lenB = arr_size(SetB);
  
  /* Sort arrays */
  BubbleSort(SetA, lenA); //Sort SetA
  BubbleSort(SetB, lenB); //Sort SetB

  /* Get the union */
  int i = 0; int j = 0; int unionSize = 0;
  while(i < lenA && j < lenB) {
    if(SetA[i] < SetB[j]) {
        printf(" %d ", SetA[i++]);
      } else if(SetA[i] > SetB[j]) {
          printf(" %d ", SetB[j++]);
      } else {
          printf(" %d ", SetB[j++]);
          i++;
      }
      unionSize++;
  }
  
  /* Print remaining elements of larger array */
  while(i < lenA) { printf(" %d ", SetA[i++]); unionSize++; }
  while(j < lenB) { printf(" %d ", SetB[j++]); unionSize++; }

  /* return the union size */
  return unionSize;
} 
开发者ID:cobookman,项目名称:HW-ECE2035,代码行数:30,代码来源:HW1-2.c

示例4: main

int main(int argc, const char * argv[]) {
    int a[N] = {12, 34, 21, 46, 89, 54, 26, 8, 6, 17};
    int flag;
    while (1) {
        printf("输入1:从小到大排序\n,输入2:从大到小排列\n输入3:退出\n");
        scanf("%d",&flag);
        switch (flag) {
            case 1:
                printf("排序前的数据为:");
                Display(a, N);
                BubbleSort(a, N, Ascending);
                printf("从小到大排列后的数据为");
                Display(a, N);
                break;
            case 2:
                printf("排序前的数据为:");
                Display(a, N);
                BubbleSort(a, N, Descending);
                printf("从大到小排列后的数据为");
                Display(a, N);
                break;
            case 3:
                return 0;
                break ;
            default:
                printf("输入数据不合法,请重新输入\n");
                break;
        }
    }
    return 0;
}
开发者ID:markmamian,项目名称:DataSt,代码行数:31,代码来源:main.c

示例5: Compare

void Compare(
    const String& repositoryRoot1,
    const String& repositoryRoot2)
{
    //
    // Create repositories:
    //

    CIMRepository r1(repositoryRoot1);
    CIMRepository r2(repositoryRoot2);

    //
    // Compare the namespaces.
    //

    Array<CIMNamespaceName> nameSpaces1 = r1.enumerateNameSpaces();
    Array<CIMNamespaceName> nameSpaces2 = r2.enumerateNameSpaces();
    BubbleSort(nameSpaces1);
    BubbleSort(nameSpaces2);
    PEGASUS_TEST_ASSERT(nameSpaces1 == nameSpaces2);

    //
    // Compare classes in each namespace:
    //

    for (Uint32 i = 0; i < nameSpaces1.size(); i++)
    {
    CompareQualifiers(r1, r2, nameSpaces1[i]);
    CompareClasses(r1, r2, nameSpaces1[i]);
    CompareInstances(r1, r2, nameSpaces1[i]);
    }
}
开发者ID:brunolauze,项目名称:pegasus,代码行数:32,代码来源:CompareRepositories.cpp

示例6: FallWtProbabilityStatistics

/*********************************************************************
函数名称: FallWtProbabilityStatistics
功    能: 概率统计方法处理落差值
说    明: 采用概率统计处理方法处理落差,避免个别大误差造成误修正
入口参数: pfs_Adapt : 自适应参数结构体
          fs32_RealFallWt : 实际得到的落差
出口参数: 
返 回 值: 统计处理后的落差值
设    计: 丛海旭               时    间: 2015-08-19
修    改:                      时    间: 
*********************************************************************/
s32 FallWtProbabilityStatistics(struct_adapt_t *pfs_Adapt, s32 fs32_RealFallWt)
{
    s32 ls32_BestFall = 0;
    u32 i = 0;
    static s32 lss32_AddFallWTemp = 0;
    static s32 lss32_FallWRecord[SLFALLWT];
    static s32 lss32_FallW_Pro[SLFALLWT];
    
    if(pfs_Adapt->u32SP3Count>(SLFALLWT-1))
    {
         for(i=0;i<(SLFALLWT-1);i++)
         {
            lss32_FallWRecord[i] = lss32_FallWRecord[i+1];
            lss32_FallW_Pro[i] = lss32_FallWRecord[i];
         }
         lss32_FallWRecord[SLFALLWT-1] = fs32_RealFallWt;
         lss32_FallW_Pro[SLFALLWT-1] = fs32_RealFallWt;
    
         BubbleSort(lss32_FallW_Pro, SLFALLWT); //冒泡排序
         ls32_BestFall = (lss32_FallW_Pro[1]+lss32_FallW_Pro[2]*3+lss32_FallW_Pro[3]*5+lss32_FallW_Pro[4]*3+lss32_FallW_Pro[5])/13;  //由于统计出落差值偏大
    }  
    else if(pfs_Adapt->u32SP3Count>=2)
    {
         lss32_FallWRecord[pfs_Adapt->u32SP3Count] = fs32_RealFallWt;
         for(i=0;i<=pfs_Adapt->u32SP3Count;i++)
         {
             lss32_FallW_Pro[i] = lss32_FallWRecord[i];
         }       
         BubbleSort(lss32_FallW_Pro, pfs_Adapt->u32SP3Count + 1); //冒泡排序
         if(pfs_Adapt->u32SP3Count>=4)
         {
             ls32_BestFall = (lss32_FallW_Pro[1]+lss32_FallW_Pro[2]*2+lss32_FallW_Pro[3])/4;
         }
         else if(pfs_Adapt->u32SP3Count>=3)
         {
             ls32_BestFall = (lss32_FallW_Pro[1]+lss32_FallW_Pro[2])/2;
         }
         else if(pfs_Adapt->u32SP3Count>=2)
         {
             ls32_BestFall = lss32_FallW_Pro[1];
         }       
         pfs_Adapt->u32SP3Count++;
    }
    else
    {
         if(pfs_Adapt->u32SP3Count==0) //如果是刚启动,清零
         {
            lss32_AddFallWTemp = 0;
         }
         lss32_FallWRecord[pfs_Adapt->u32SP3Count] = fs32_RealFallWt;
         pfs_Adapt->u32SP3Count++;       
         lss32_AddFallWTemp += fs32_RealFallWt;
         ls32_BestFall = lss32_AddFallWTemp/pfs_Adapt->u32SP3Count;       
    }
    
    return ls32_BestFall;
   
}
开发者ID:DharmaPatil,项目名称:-,代码行数:69,代码来源:Adaptation.c

示例7: SP2LinearKProbabilityStatistics

/*********************************************************************
函数名称: SP2LinearKProbabilityStatistics
功    能: 概率统计方法处理小投线性拟合K值
说    明: 该函数一定放在FallWtProbabilityStatistics函数前面
          因为FallWtProbabilityStatistics函数中有对pfs_Adapt->u32SP3Count++的操作
入口参数: pfs_Adapt=自适应参数结构体
          fs32_KThisTime=实际得到的本次K值
出口参数: 
返 回 值: 统计处理后的K值
设    计: 丛海旭               时    间: 2015-8-25
修    改:                      时    间: 
*********************************************************************/
s32 SP2LinearKProbabilityStatistics(struct_adapt_t *pfs_Adapt, s32 fs32_KThisTime)
{
    s32 ls32_Result = 0;
    u32 i = 0;
    static s32 lss32_AddFallWTemp = 0;
    static s32 lss32_KRecord[SLFALLWT];
    static s32 lss32_K_Pro[SLFALLWT];
        
    if(pfs_Adapt->u32SP3Count>(SLFALLWT-1))
    {
         for(i=0;i<(SLFALLWT-1);i++)
         {
            lss32_KRecord[i] = lss32_KRecord[i+1];
            lss32_K_Pro[i] = lss32_KRecord[i];
         }
         lss32_KRecord[SLFALLWT-1] = fs32_KThisTime;
         lss32_K_Pro[SLFALLWT-1] = fs32_KThisTime;
    
         BubbleSort(lss32_K_Pro, SLFALLWT); //冒泡排序
         ls32_Result = (lss32_K_Pro[1]+lss32_K_Pro[2]*3+lss32_K_Pro[3]*5+lss32_K_Pro[4]*3+lss32_K_Pro[5])/13;  //由于统计出落差值偏大
    }  
    else if(pfs_Adapt->u32SP3Count>=2)
    {
         lss32_KRecord[pfs_Adapt->u32SP3Count] = fs32_KThisTime;
         for(i=0;i<=pfs_Adapt->u32SP3Count;i++)
         {
             lss32_K_Pro[i] = lss32_KRecord[i];
         }       
         BubbleSort(lss32_K_Pro, pfs_Adapt->u32SP3Count + 1); //冒泡排序
         if(pfs_Adapt->u32SP3Count>=4)
         {
             ls32_Result = (lss32_K_Pro[1]+lss32_K_Pro[2]*2+lss32_K_Pro[3])/4;
         }
         else if(pfs_Adapt->u32SP3Count>=3)
         {
             ls32_Result = (lss32_K_Pro[1]+lss32_K_Pro[2])/2;
         }
         else if(pfs_Adapt->u32SP3Count>=2)
         {
             ls32_Result = lss32_K_Pro[1];
         }       
//         pfs_Adapt->u32SP3Count++;
    }
    else
    {
         if(pfs_Adapt->u32SP3Count==0) //如果是刚启动,清零
         {
            lss32_AddFallWTemp = 0;
         }
         lss32_KRecord[pfs_Adapt->u32SP3Count] = fs32_KThisTime;
//         pfs_Adapt->u32SP3Count++;       
         lss32_AddFallWTemp += fs32_KThisTime;
         ls32_Result = lss32_AddFallWTemp/(pfs_Adapt->u32SP3Count + 1);       
    }
    
    return ls32_Result;
}
开发者ID:DharmaPatil,项目名称:-,代码行数:69,代码来源:Adaptation.c

示例8: OutputShapesInCorrectOrder

void OutputShapesInCorrectOrder(std::vector<std::shared_ptr<CShape>> & figures)
{
	BubbleSort(figures, true);
	std::cout << std::endl << "Shapes sorted by area:" << std::endl << std::endl;
	OutputShapes(figures);
	BubbleSort(figures, false);
	std::cout << std::endl << "Shapes sorted by perimeter:" << std::endl << std::endl;
	OutputShapes(figures);

}
开发者ID:dlxgit,项目名称:OOP,代码行数:10,代码来源:HandleShapes.cpp

示例9: CompareClasses

void CompareClasses(
    CIMRepository& r1,
    CIMRepository& r2,
    const CIMNamespaceName& namespaceName)
{
    Array<CIMName> classNames1 = r1.enumerateClassNames(namespaceName);
    Array<CIMName> classNames2 = r2.enumerateClassNames(namespaceName);
    BubbleSort(classNames1);
    BubbleSort(classNames2);


    PEGASUS_TEST_ASSERT(classNames1 == classNames2);

    for (Uint32 i = 0; i < classNames1.size(); i++)
    {
    CIMClass class1 = r1.getClass(namespaceName, classNames1[i]);
    CIMClass class2 = r2.getClass(namespaceName, classNames2[i]);

    if (verbose)
    {
        cout << "testing class " << namespaceName.getString() << "/";
        cout << classNames1[i].getString() << "..." << endl;
    }

    if (!class1.identical(class2))
    {
        PutClass("file1", class1);
        PutClass("file2", class2);

        cout << "=========================================================";
        cout << "=========================================================";
        cout << endl;
        cout << "ERROR: not identical! - ";


        cout << "ERROR FOUND testing class: " << namespaceName.getString();
        cout << "/";
        cout << classNames1[i].getString();

        cout << " .... differences follow:" << endl << endl;

        if (system("diff file1 file2") == -1)
        {
            cout << "Error:  system(\"diff file1 file2\") failed." << endl;
        }

        if (verbose)
        {
            XmlWriter::printClassElement(class1, cout);
            XmlWriter::printClassElement(class2, cout);
        }
        failures++;
    }
    }
}
开发者ID:brunolauze,项目名称:pegasus,代码行数:55,代码来源:CompareRepositories.cpp

示例10: XSort

void XSort(ElementType S[], long N, int X)
{
    switch (X)
    {
        case 0: BubbleSort(S, N); break;
        case 1: InsertionSort(S, N); break;
        case 2: ShellSort(S, N); break;
        case 3: HeapSort(S, N); break;
        case 4: MergeSortByRecursiveImpl(S, N); break;
        case 5: MergeSortByNonRecursiveImpl(S, N); break;
        case 6: QuickSort(S, N); break;
        default: BubbleSort(S, N); break;
    }
}
开发者ID:LuoYY,项目名称:DataStructures,代码行数:14,代码来源:DS_05_01_Sort.c

示例11: main

int main(){

   Initialize(Array);
   BubbleSort(Array);

   return 0;
}
开发者ID:Paschalis,项目名称:adapt16_benchmarks,代码行数:7,代码来源:base.c

示例12: main

void main()
{
	int shuzu[SIZE],i;

	srand(time(NULL));

	for(i=0;i<SIZE;i++)
	{
		shuzu[i]=rand()/1000 + 100;
	}

	printf("排序前的数组为:\n");
	for(i=0;i<SIZE;i++)
	{
		printf("%d  ",shuzu[i]);
	}

	printf("\n");

	BubbleSort(shuzu,SIZE);

	printf("排序后的数组:\n");
	for(i=0;i<SIZE;i++)
	{
		printf("%d  ",shuzu[i]);
	}

	printf("\n");
}
开发者ID:cswanghan,项目名称:code,代码行数:29,代码来源:main.cpp

示例13: QuickSort

/*******************************************************************
  QuickSort : Perform the quick sort operation. If size of array is
            : below the threshold, then use bubble sort, else
	    : divide the job and insert one part into the task stack
 *******************************************************************/
QuickSort(register int i, register int j)
{
    register int pivot, k;

QSORT:
    /* pivot is index of the pivot element */
    if(j-i+1 < BubbleThresh) {
        if(bubble) BubbleSort(i,j);
        else LocalQuickSort(i,j);
        return;
    }
    pivot = FindPivot(i,j);
    k = Partition(i,j,gMem->A[pivot]);
    if(k-i > j-k) {
        /* The lower half [i through (k-1)] contains more entries.      */
        /* Put the other half into the queue of unsorted subarrays      */
        /* and recurse on the other half.                               */
        PushWork(k,j);
        j=k-1;
        goto QSORT;
        /*    QuickSort(i, k-1); */ /* eliminating tail recursion */
    }
    else {
        PushWork(i,k-1);
        i=k;
        goto QSORT;
        /*     QuickSort(k,j); */ /* Eliminating tail recursion */
    }
}
开发者ID:vag1830,项目名称:MultiprocSimulationLabs,代码行数:34,代码来源:quicksort.c

示例14: main

int main(){
  long ct_repeat=0;
  long ct_repeat_max=1;
  int ct_return=0;

#ifdef XOPENME
  xopenme_init(1,2);
#endif

  if (getenv("CT_REPEAT_MAIN")!=NULL) ct_repeat_max=atol(getenv("CT_REPEAT_MAIN"));

#ifdef XOPENME
  xopenme_clock_start(0);
#endif

  for (ct_repeat=0; ct_repeat<ct_repeat_max; ct_repeat++)
  {
   Initialize(Array);
   BubbleSort(Array);
  }

#ifdef XOPENME
  xopenme_clock_end(0);
  xopenme_dump_state();
  xopenme_finish();
#endif

   return 0;
}
开发者ID:ctuning,项目名称:reproduce-adapt16,代码行数:29,代码来源:base.c

示例15: main

int main(void)
{
    int x[20]={17,10,13,14,15,6,3,2,9,8,18,7,12,11,16,4,1,20,5,19};
    FsOpenWindow(16,16,400,400,1);
    BubbleSort(20, x);
    return 0;
}
开发者ID:hewolf,项目名称:Engineering-Computation,代码行数:7,代码来源:ps4-1.cpp


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