VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

 

Code Snippets

  

VB.NET Source Code


Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,574 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,189 people online right now. Registration is fast and FREE... Join Now!



Submitted By: janmichaelintia
Actions:
Rating:
Views: 251

Language: VB.NET

Last Modified: July 2, 2009
Instructions: This snippet sorts an array of numbers ascendingly.

Snippet


  1. Public Function NumberSorting(ByVal numbers() As Integer) _
  2.     As Integer()
  3.  
  4.         ' Iterate through array of numbers
  5.         ' For every iteration, index 'j' will
  6.         ' act as a comparator
  7.         For j As Integer = 0 To numbers.Length - 1
  8.  
  9.             For x As Integer = 0 To numbers.Length - 1
  10.  
  11.                 ' Compare each numbers of the array
  12.                 ' with the comparator
  13.                 If numbers(x) > numbers(j) Then
  14.  
  15.                     ' If a number preceeding the comparator
  16.                     ' is greater than the comparator
  17.                     ' exchange/switch the numbers
  18.                     numbers(x) = numbers(x) + numbers(j)
  19.                     numbers(j) = numbers(x) - numbers(j)
  20.                     numbers(x) = numbers(x) - numbers(j)
  21.                 End If
  22.             Next
  23.         Next
  24.  
  25.         Return numbers
  26.  
  27.  End Function
  28.  
  29.  
  30.  
  31. ' Usage Example:
  32.  
  33. Dim numbers() As Integer = {501, 66, 502, 120, 1, 8, 7, 500}
  34. Dim sortedNumberList() As Integer = NumberSorting(numbers)
  35.  
  36. ' Output: sortedNumberList() = {1, 7, 8, 66, 120, 500, 501, 502}
  37.      

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month