C # Data Structure Sorting Algorithm

Source: Internet
Author: User

C # Data Structure sorting algorithm, which includes Bubble sorting. For more information, see Lao Zhao's CodeTimer and eaglet performance counters. Thank you ~~

Let's get started with our sorting algorithm ~

Before performing the C # Data Structure sorting algorithm, we first define a 100-bit random sequence to test the performance of various C # Data Structure sorting algorithms.

The Code is as follows:

 
 
  1. ///<Summary> 
  2. /// Randomly generate an array of 100 bits
  3. /// Summary> 
  4. ///<Returns>Returns the generated array. Returns> 
  5. Publicstaticint [] RandomArray ()
  6. {
  7. Randomran=NewRandom();
  8. Int []Arr=Newint[100];
  9. Inttem;
  10. For (Inti=0; I<100; I ++)
  11. {
  12. Tem=Ran. Next (1,100 );
  13. Arr [I] = tem;
  14. }
  15. Returnarr;
  16. }

Bubble Sort)

Basic Idea: Compare key codes of adjacent records. If the key codes recorded earlier are greater than the key codes recorded later, they are exchanged. Otherwise, they are not exchanged.

 
 
  1. ///<Summary> 
  2. /// Bubble Sorting Algorithm
  3. /// Summary> 
  4. PublicclassBubbleSort: IAction
  5. {
  6. # RegionIAction Member
  7. PublicvoidAction ()
  8. {
  9. Int []Array=Program. RandomArray ();
  10. For (Inta=0;<Array. Length; A ++)
  11. {
  12. Intitem=0;
  13. For (Intb=Array. Length-1; B>A; B --)
  14. {
  15. If (array [B]<Array[B-1])
  16. {
  17. Item=Array[B];
  18. Array [B] = array [b-1];
  19. Array [b-1] = item;
  20. }
  21. }
  22. }
  23. }
  24. # Endregion
  25. }
  1. C # Call Windows API functions
  2. C # Calling Outlook APIs
  3. C # connect to Access and SQL Server databases
  4. Introduction to C # API call problems
  5. C # Call Excel and additional code

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.