zoukankan      html  css  js  c++  java
  • string字母排序,

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace ConsoleApplication1
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             string[] str =  { "student","iphone","abs","ball","wc"};
    14             SortStringArray(str,SortType.rise);
    15 
    16             for (int i = 0; i < str.Length; i++)
    17             {
    18                 Console.WriteLine(str[i]);
    19             }
    20 
    21             Console.ReadKey();
    22         }
    23 
    24 
    25 
    26         //按字母排序
    27         static void SortStringArray(string [] array,SortType type) 
    28         {
    29             string temp = null;
    30 
    31             //降序
    32             if (type == SortType.drop)
    33             {
    34                 for (int i = 0; i < array.Length; i++)
    35                 {
    36                     for (int j = i; j < array.Length; j++)
    37                     {
    38                         if ((int)array[i][0] < (int)array[j][0])
    39                         {
    40                             temp = array[i];
    41                             array[i] = array[j];
    42                             array[j] = temp;
    43                         }
    44                     }
    45                 }
    46             }//升序
    47             else if(type == SortType.rise)
    48             {
    49                 for (int i = 0; i < array.Length; i++)
    50                 {
    51                     for (int j = i; j < array.Length; j++)
    52                     {
    53                         if ((int)array[i][0] > (int)array[j][0])
    54                         {
    55                             temp = array[i];
    56                             array[i] = array[j];
    57                             array[j] = temp;
    58                         }
    59                     }
    60                 }
    61             }
    62 
    63 
    64 
    65         }
    66 
    67         public enum SortType
    68         {
    69             drop,
    70             rise
    71         }
    72 
    73     }
    74 
    75 }

    冒泡算法对string数组排序O(∩_∩)O~

    新人求关照,求大家多多指点

    如果你感兴趣,你可以把你妹妹介绍给我
  • 相关阅读:
    类别的三个作用
    require()
    commonJS
    ng-app&data-ng-app
    《css网站布局实录》(李超)——读书札记
    高性能JS(读书札记)
    两个同级div重叠的情况
    前端性能优化
    正则表达式
    ajax
  • 原文地址:https://www.cnblogs.com/plateFace/p/4148450.html
Copyright © 2011-2022 走看看