简单算法摘录集合

    PS:最近处于找工作状态,基本都会有算法笔试题,我之前基本没有接触过算法,所以结果可想而知啊,哈哈

  1、简单的冒泡排序法基本思想:两两比较相邻记录的关键字,如果反序则交换,直到没有反序的记录为止。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication.BubbleSortAlgorithm
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             int[] dList = { 15, 1, 12, 4, 35, 2, 36, 42, 33, 7 };
14             int temp;
15             int length = dList.Length;
16             for (int i = 0; i < length; i++)
17             {
18                 for (int j = i + 1; j < length; j++)
19                 {
20                     if (dList[i] > dList[j])
21                     {
22                         temp = dList[i];
23                         dList[i] = dList[j];
24                         dList[j] = temp;
25                     }
26                 }
27             }
28 
29             foreach(int a in dList)
30             {
31                 Console.WriteLine(a);
32             }
33             Console.Read();
34         }
35     }
36 }
简单的冒泡排序

结果:

 

 2、

原文地址:https://www.cnblogs.com/ganqiyin/p/4012136.html