zoukankan      html  css  js  c++  java
  • 冒泡排序(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();
            }

        }

    }

  • 相关阅读:
    rest-framework框架——解析器、ur控制、分页、响应器、渲染器
    rest-framework框架——认证、权限、频率组件
    rest-framework框架——视图三部曲
    rest-framework框架——APIView和序列化组件
    Django——CBV与FBV
    CRM——权限
    CRM——销售与客户
    CRM——讲师与学生
    CRM——起步
    jsp标签
  • 原文地址:https://www.cnblogs.com/solo/p/610138.html
Copyright © 2011-2022 走看看