zoukankan      html  css  js  c++  java
  • 排序

    //C++ 排序方法的总结
    #include <iostream>
    #include <vector>
    using namespace std;
    
    /*
    采用插入法进行排序
    */
    void InsertArray(int a[],int n, int* &b)
    {
    	int temp;
        int j;
    	for(int i = 0;i<n-1;i++)
    	{
    		j  = i;
    		while(a[j]>a[j+1])  //后者小于前者,交换
    		{
    			temp = a[j];
    			a[j] = a[j+1];
    			a[j+1] = temp;
    
    			if(j>0)
    			{
    				j--;
    			}
    		}
    
    	}
    	b = a;
    }
    
    /*
    采用冒泡排序
    */
    void SortArray(int a[], int n)
    {
    	int temp ;
    	for (int i = 1;i<n;i++)//n-1次
    		for (int j = 0;j<n-i;j++)//n-i次
    		{
    			if (a[j]>a[j+1])
    			{
    				temp = a[j];
    				a[j]= a[j+1];
    				a[j+1] = temp;
    			}
    		}
    }
    
    
    void main()
    {
    	int *b;
    	int a[13]= {43,21,89,15,43,28,24,5,67,8,78,23,46};
    // 	InsertArray(a,13,b);
    // 	cout<<"选择排序的结果"<<endl;
    // 	for(int k = 0;k<13;k++)
    // 	{
    // 		cout<<*(b+k)<<' ';
    // 	}
     	cout<<"冒泡排序的结果"<<endl;
    	SortArray(a,13);
    	for(int k = 0;k<13;k++)
    	{
    		cout<<a[k]<<' ';
    	}
    }
    
  • 相关阅读:
    位置匹配
    匹配重复
    使用元字符
    匹配一组字符
    匹配任意单个字符
    python-全局替换程序
    python37-encode与decode
    python37-能检测文件编码的模块
    super方法
    类-易错题
  • 原文地址:https://www.cnblogs.com/CBDoctor/p/2628401.html
Copyright © 2011-2022 走看看