Just3ala2
08-20-04, 08:21 AM
hi to all
i finished my bubble sort visualizaing but i need the output in a different way
i want the user to click on "Draw" in each iteration to get the output of each iteration
i would appreciate quick help
this is the code of my program and the full program in the attached file
Option Strict On
Public Class BubbleSort
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Dim myArray(10) As Decimal 'a global array that holds the inputs
Dim signal As Integer = 0 ' for the btndraw which assigns the values on the first click
Private Sub BubbleSort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
If signal = 0 Then
assignArray()
signal += 1
btnDraw.PerformClick() 'to draw after assigning the array values
Else 'drawing method
Pic1.Height = Convert.ToInt32(myArray(1)) * 3
Pic2.Height = Convert.ToInt32(myArray(2)) * 3
Pic3.Height = Convert.ToInt32(myArray(3)) * 3
Pic4.Height = Convert.ToInt32(myArray(4)) * 3
Pic5.Height = Convert.ToInt32(myArray(5)) * 3
Pic6.Height = Convert.ToInt32(myArray(6)) * 3
Pic7.Height = Convert.ToInt32(myArray(7)) * 3
Pic8.Height = Convert.ToInt32(myArray(8)) * 3
Pic9.Height = Convert.ToInt32(myArray(9)) * 3
Pic10.Height = Convert.ToInt32(myArray(10)) * 3
End If
End Sub
Private Function assignArray() As Array 'assigning function
myArray(1) = nud1.Value
myArray(2) = nud2.Value
myArray(3) = nud3.Value
myArray(4) = nud4.Value
myArray(5) = nud5.Value
myArray(6) = nud6.Value
myArray(7) = nud7.Value
myArray(8) = nud8.Value
myArray(9) = nud9.Value
myArray(10) = nud10.Value
End Function
Private Function Sorting() As Integer 'Bubble Sort
Dim outcounter As Integer = 0
Dim incounter As Integer = 0
Dim temp As Decimal
For outcounter = 1 To 10
For incounter = 1 To 9
If myArray(incounter) > myArray(incounter + 1) Then
If myArray(incounter) <> myArray(incounter + 1) Then
temp = myArray(incounter)
myArray(incounter) = myArray(incounter + 1)
myArray(incounter + 1) = temp
End If
End If
Next
Next
Return 0
End Function
Private Sub btnSort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSort.Click
Sorting()
End Sub
Private Sub TimerBubbles_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerBubbles.Tick
'Just for the some visual effects
picBub1.Top -= 4
If picBub1.Top < -20 Then
picBub1.Top = Me.Height - 20
End If
picBub2.Top -= 4
If picBub2.Top < -20 Then
picBub2.Top = Me.Height - 20
End If
picBub3.Top -= 4
If picBub3.Top < -20 Then
picBub3.Top = Me.Height - 20
End If
picBub4.Top -= 4
If picBub4.Top < -20 Then
picBub4.Top = Me.Height - 20
End If
End Sub
End Class
i finished my bubble sort visualizaing but i need the output in a different way
i want the user to click on "Draw" in each iteration to get the output of each iteration
i would appreciate quick help
this is the code of my program and the full program in the attached file
Option Strict On
Public Class BubbleSort
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Dim myArray(10) As Decimal 'a global array that holds the inputs
Dim signal As Integer = 0 ' for the btndraw which assigns the values on the first click
Private Sub BubbleSort_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnDraw_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDraw.Click
If signal = 0 Then
assignArray()
signal += 1
btnDraw.PerformClick() 'to draw after assigning the array values
Else 'drawing method
Pic1.Height = Convert.ToInt32(myArray(1)) * 3
Pic2.Height = Convert.ToInt32(myArray(2)) * 3
Pic3.Height = Convert.ToInt32(myArray(3)) * 3
Pic4.Height = Convert.ToInt32(myArray(4)) * 3
Pic5.Height = Convert.ToInt32(myArray(5)) * 3
Pic6.Height = Convert.ToInt32(myArray(6)) * 3
Pic7.Height = Convert.ToInt32(myArray(7)) * 3
Pic8.Height = Convert.ToInt32(myArray(8)) * 3
Pic9.Height = Convert.ToInt32(myArray(9)) * 3
Pic10.Height = Convert.ToInt32(myArray(10)) * 3
End If
End Sub
Private Function assignArray() As Array 'assigning function
myArray(1) = nud1.Value
myArray(2) = nud2.Value
myArray(3) = nud3.Value
myArray(4) = nud4.Value
myArray(5) = nud5.Value
myArray(6) = nud6.Value
myArray(7) = nud7.Value
myArray(8) = nud8.Value
myArray(9) = nud9.Value
myArray(10) = nud10.Value
End Function
Private Function Sorting() As Integer 'Bubble Sort
Dim outcounter As Integer = 0
Dim incounter As Integer = 0
Dim temp As Decimal
For outcounter = 1 To 10
For incounter = 1 To 9
If myArray(incounter) > myArray(incounter + 1) Then
If myArray(incounter) <> myArray(incounter + 1) Then
temp = myArray(incounter)
myArray(incounter) = myArray(incounter + 1)
myArray(incounter + 1) = temp
End If
End If
Next
Next
Return 0
End Function
Private Sub btnSort_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSort.Click
Sorting()
End Sub
Private Sub TimerBubbles_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerBubbles.Tick
'Just for the some visual effects
picBub1.Top -= 4
If picBub1.Top < -20 Then
picBub1.Top = Me.Height - 20
End If
picBub2.Top -= 4
If picBub2.Top < -20 Then
picBub2.Top = Me.Height - 20
End If
picBub3.Top -= 4
If picBub3.Top < -20 Then
picBub3.Top = Me.Height - 20
End If
picBub4.Top -= 4
If picBub4.Top < -20 Then
picBub4.Top = Me.Height - 20
End If
End Sub
End Class