zoukankan      html  css  js  c++  java
  • 数组【冒泡法排序】

     1 #include<iostream.h>
     2 void PopSort(int array[],int n);//函数声明
     3 void main()
     4 {
     5     //测试函数
     6     int array[10]={23,32,12,11,31,90,100,55,26,22};
     7     PopSort(array,10);
     8     for(int i=0;i<10;i++)
     9     {
    10         cout<<array[i]<<"\t";
    11         if((i+1)%5==0)
    12         {
    13             cout<<endl;
    14         }
    15     }
    16 }
    17 /*****************************************************
    18 *函数名称:PopSort(int array[],int n)
    19 *参数:
    20 *  int array[],待排序的数组数据
    21 *  int n,排序数据个数,即数组大小
    22 *功能描述:使用冒泡法进行数组排序,升序排序
    23 *****************************************************/
    24 void PopSort(int array[],int n)
    25 {
    26     int i,j;
    27     int temp;//中间变量
    28     for(i=0;i<n;i++)//for(i=1;i<n-1;i++)
    29     {
    30         for(j=0;j<n-i-1;j++)
    31         {
    32             if(array[j]>array[j+1])//j<n-i-1
    33             {
    34                 //数据交换
    35                 temp=array[j];
    36                 array[j]=array[j+1];
    37                 array[j+1]=temp;
    38             }
    39         }
    40     }
    41 }
  • 相关阅读:
    .net core 下编码问题
    spring一些简单小注意知识点
    使用ORM插入数据报错 Duplicate entry '0' for key 'PRIMARY'
    python:零散记录
    python:端口扫描邮件推送
    redis:哨兵集群配置
    redis:安装配置主从
    iptables:ipset批量管理ip
    Django:调用css、image、js
    Python:字体颜色
  • 原文地址:https://www.cnblogs.com/wintergrass/p/1992114.html
Copyright © 2011-2022 走看看