BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Visual Programming (http://bzupages.com/237-visual-programming/)
-   -   Program for Sorting the elements of an Array (bubble Sort) VB Code (By Sheraz) (http://bzupages.com/f237/program-sorting-elements-array-bubble-sort-vb-code-sheraz-7194/)

.BZU. 15-12-2009 11:07 PM

Program for Sorting the elements of an Array (bubble Sort) VB Code (By Sheraz)
 
Code:

Module Module1
 
      Sub Main()
          Dim ar As Integer()
          Dim temp As Integer
          Dim my_index As Integer
          ar = New Integer() {15, 8, 1, 6, 34, 7, 5, 342, 4, 9}
          my_index = ar.GetUpperBound(0)
 
          For j = 0 To 8
 
              For i = 0 To my_index - 1    ' 1 is subtrcted to avoid INDEX OUT OF RANGE
  If ar(i) > ar(i + 1) Then
                      temp = ar(i)
                      ar(i) = ar(i + 1)
  ar(i + 1) = temp
                  End If
              Next
              my_index = my_index - 1
 
          Next
 
 
          For k = 0 To ar.GetUpperBound(0)
              Console.WriteLine(ar(k))
 
          Next
 
          Console.ReadLine()
      End Sub
 
  End Module
 
 
 



All times are GMT +5. The time now is 11:58 AM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.