..


Sponsored Links

Sorting Algorithms in C #

Article written by Vincent Gaglio
Page 1 of 7

Sorting a list of objects is one of the fundamental problems of computing. There are several ways to do this and they fall in the so-called sorting algorithms. Some of these algorithms are simple and intuitive, while others are more complex and allow for better performance.

Among the best known and most popular sorting algorithms are:

  • Bubble Sort
  • Heap Sort
  • Insertion Sort
  • Merge Sort
  • Quick Sort
  • Selection Sort
  • Shell Sort

BUBBLE SORT

The Bubble Sort works by comparing each element of a list with the next item, instead of exchanging them if necessary. The algorithm repeats this process until it runs the entire list without exchanges between elements. The name bubble (bubble) stems from the way in which elements are ordered: the smaller ones go back to their correct positions in the list, just like bubbles in a fizzy drink. Because of this way of doing this algorithm is considered the most inefficient among those listed.

Here's the code of an implementation of this algorithm:






 / / Array of integers







 private int [] a = new int [100];









 / / Number of elements in the







 private int x;









 public void BubbleSort ()







 {



  



 int i;



  



 int j;



  



 int temp;





  



 for (i = (x - 1); i> = 0; i -)



  



 {



    



 for (j = 1 j <= i, j + +)



    



 {



      



 if (a [j - 1]> a [j])



      



 {



        



 temp = a [j - 1];



        



 a [j - 1] = a [j];



        



 a [j] = temp;



      



 }



    



 }



  



 }







 }



In the same category ...
E-Learning
ASP Zero (Ebook) ASP Zero (Ebook)
Learning Microsoft ASP and VBScript from scratch. At only 29 €.
PHP (Course) PHP (Course)
Full course for creating dynamic Web sites. From 49 €.
Web Marketing (Course) Web Marketing (Course)
Site promotion, search engines and marketing. From 39 €.
Sponsored Links