Simple Algorithm excerpt set

Source: Internet
Author: User

    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 Program10     {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、

 

简单算法摘录集合

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.