• 冒泡排序(C#数据结构学习九)


    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace SoloDataStructure
    {
        
    class MyBubbleSort
        
    {
            
    //冒泡排序
            static void BubbleSort(int[] arr)
            
    {
                
    int n = arr.Length;
                
    for (int i = 0; i < n - 1; i++)  //做n-1趟排序
                {
                    
    bool noswap = true;    //未交换标志
                    for (int j = n - 1; j > i; j--)
                    
    {
                        
    if (arr[j] < arr[j-1])
                        
    {
                            
    //swap记录
                            int temp = arr[j];
                            arr[j] 
    = arr[j-1];
                            arr[j
    -1= temp;
                            noswap 
    = false;
                        }

                    }

                    
    if (noswap)
                        
    return;
                }

            }

            
    static void Main(string[] args)
            
    {
                
    int[] arr = new int[] {99,884,9,2,77,32,11,46};
                BubbleSort(arr);
                Console.Write(
    "Data After BubbleSort:");
                
    foreach (int i in arr)
                
    {
                    Console.Write(i
    +",");
                }

                Console.ReadLine();
            }

        }

    }

  • 相关阅读:
    Aerospike系列:4:简单的增删改查aql
    Aerospike系列:3:aerospike特点分析
    MySQL事物系列:2:事物的实现
    MySQL事物系列:1:事物简介
    MySQL 源码系列:1:窥探篇
    MySQL 内存和CPU优化相关的参数
    Aerospike系列:2:商业版和社区版的比较
    Aerospike系列:1:安装
    MDX Cookbook 08
    MDX Cookbook 07
  • 原文地址:https://www.cnblogs.com/solo/p/610138.html
Copyright © 2020-2023  润新知