100% found this document useful (1 vote)
61 views

Sorting Algorithm For Bca

This document contains code for sorting numbers. It defines variables to store the number of items in an array and the array itself. It includes buttons to add numbers to the array, sort the numbers in ascending order and display the sorted array, clear all fields, and close the form. Numbers are entered into an array using a textbox and button, then sorted using a bubble sort algorithm that compares and swaps array items if out of order. The sorted numbers are then displayed in a separate list box.

Uploaded by

Sam Khar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
61 views

Sorting Algorithm For Bca

This document contains code for sorting numbers. It defines variables to store the number of items in an array and the array itself. It includes buttons to add numbers to the array, sort the numbers in ascending order and display the sorted array, clear all fields, and close the form. Numbers are entered into an array using a textbox and button, then sorted using a bubble sort algorithm that compares and swaps array items if out of order. The sorted numbers are then displayed in a separate list box.

Uploaded by

Sam Khar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

// Sorting numbers

Public Class Form1


Dim n, no, t As Integer
Dim a(10) As Integer

Private Sub GroupBox1_Enter(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GroupBox1.Enter

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
Static i As Integer
n = Val(TextBox1.Text)
TextBox2.Focus()

If (i < n) Then
a(i) = Val(TextBox2.Text)
ListBox1.Items.Add(a(i))
i = i + 1

End If
If (i >= n) Then
MsgBox("array full")

End If

TextBox2.Clear()
TextBox2.Focus()

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

TextBox1.Focus()

End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object,


ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
n = Val(TextBox1.Text)
For i = 0 To n - 2
For j = i + 1 To n - 1
If (a(j) > a(i)) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next
Next
For i = 0 To n - 1
ListBox2.Items.Add(a(i))
Next

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button3.Click
Me.Close()
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button4.Click
TextBox1.Clear()
TextBox2.Clear()
ListBox1.Items.Clear()
ListBox2.Items.Clear()

End Sub

End Class

You might also like