博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【2017-3-1】冒泡排序
阅读量:4604 次
发布时间:2019-06-09

本文共 652 字,大约阅读时间需要 2 分钟。

冒泡排序

依次比较相邻的两个数,将小数放在前面,大数放在后面。

 

数组中两个变量进行交换                                         //对数组中两个变量进行交换,是冒泡排序中最基本的步骤

         int [] s = new int[]{1,5,7};

         int  a = s [0]; 

         s [0] = s [s.Length-1];

         s [s.Length-1] = int a ;

         for (int i =0;i<s.Length;i++);

         { 

                 Console.WriteLine(s[i]);

          }

 

 

    冒泡排序                                                                //冒泡排序最基本的格式,格式固定,很重要,记住                                                

                    int [ ] ss = new int[ ]{2,1,5,3,4};

                    int  temp;

                    for ( int i = 0 ; i < ss.Length ; i ++ )                    //抽取第一个变量    

                   {

                        for ( int j = i + 1 ; j < ss.Length ; j++  )           // 抽取第二个变量             

                        {

                              if ( ss[ i ]< ss[ j ]    )                                //比较,交换位置

                              {

                                     temp = ss[ i ];                                     

                                     ss[ i ]= ss[ j ];

                                     ss[ j ];=temp;

                                }

                          }

                      }

                      for( int i <0 ; i< ss.Length ; i++ )                         // 输出 

                    {

                         Console.WriteLine(  ss [ i ] );

                      }

                      Console.ReadLine();

转载于:https://www.cnblogs.com/hanqi0216/p/6525768.html

你可能感兴趣的文章
CSS-上下文选择器
查看>>
ionic repeat 重复最后一个时要执行某个函数
查看>>
1.初识代码审计-基础
查看>>
APC注入
查看>>
No enclosing instance of type Hello is accessible
查看>>
windows SVN搭建
查看>>
Scrum立会报告+燃尽图(Beta阶段第二周第二次)
查看>>
动态代理
查看>>
WCF 中,出现The remote server returned an unexpected response: (400) Bad Request.
查看>>
缓存概要
查看>>
vue项目中使用百度地图的方法
查看>>
[Vue-rx] Stream an API using RxJS into a Vue.js Template
查看>>
[Javascript] lodash: memoize() to improve the profermence
查看>>
手写符合Promise/A+规范的Promise
查看>>
Python time和datetime模块
查看>>
JPA、JTA、XA相关索引
查看>>
查询语句的练习
查看>>
Java EE的map
查看>>
webdriver.py--解说
查看>>
windows 下配置Eclipse che
查看>>