Sorting program help

Bubble sort,Selection sort, shell sort program

Page 1 of 1

1 Replies - 3320 Views - Last Post: 17 June 2008 - 06:57 AM Rate Topic: -----

#1 ladyluck  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-June 08

Sorting program help

Posted 17 June 2008 - 05:40 AM

Im trying to make a program that lets the user enter 8 integers and then the program sorts them using three different methods: Bubble sort, Selection sort, and shell sort. The thing is, im saving the information entered by the user in an array and then when i try to run the function for sorting the program says that the array cant be converted to Integer and whatnot. I need to know if theres another way to save the data enterd by the user so the program works better. Heres my code:

	Dim NumArray(7) As Integer
	Dim Tempor1, Tempor2, Tempor3 As Integer
	Dim promt As String = "Please enter an integer:"


	Dim i As Integer

	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		' This for next controls the entered numbers and asigns them to the array.

		For i = LBound(NumArray) To UBound(NumArray)
			NumArray(i) = InputBox(promt, , "Input Integers")

		Next i
	  
		'Llamar funciones de sorting.

		Call BubbleSortNumbers(Tempor1)
		TextBox1.Text = Tempor1
		Call SelectionSortNumbers(Tempor2)
		TextBox2.Text = Tempor2
		Call ShellSortNumbers(Tempor3)
		TextBox3.Text = Tempor3

	End Sub

	'Bubble sort

	Sub BubbleSortNumbers(ByVal iArray As Integer)
		Dim index1 As Long
		Dim index2 As Long
		Dim tempor As Long

		For index1 = UBound(iArray) To LBound(iArray) Step -1
			For index2 = LBound(iArray) + 1 To index1
				If iArray(index2 - 1) = iArray(index2) Then
					iArray(index2) = tempor
				End If
			Next index2
		Next index1
	End Sub

	'Selection sort 

	Sub SelectionSortNumbers(ByVal vArray)

		Dim index1 As Long
		Dim index2 As Long
		Dim min As Long
		Dim tempor As Long

		For index1 = LBound(vArray) To UBound(vArray) - 1
			min = index1
			For index2 = index1 + 1 To UBound(vArray)
				If vArray(index2) < vArray(min) Then min = index2
			Next index2
			tempor = vArray(min)
			vArray(min) = vArray(index1)
			vArray(index1) = tempor
		Next index1
	End Sub

	'Shell Sort

	Sub ShellSortNumbers(ByVal vArray)
		Dim index1 As Long
		Dim hold As Long
		Dim value As Long
		Dim tempor As Long

		value = LBound(vArray)
		Do
			value = 3 * value + 1
		Loop Until value > UBound(vArray)
		Do
			value = value / 3
			For index1 = value + LBound(vArray) To UBound(vArray)
				tempor = vArray(index1)
				hold = index1
				Do While vArray(hold - value) > tempor
					vArray(hold) = vArray(hold - value)
					hold = hold - value
					If hold < value Then Exit Do
				Loop
				vArray(hold) = tempor
			Next index1
		Loop Until value = LBound(vArray)
	End Sub
End Class 


And heres how the program should look like:

Posted Image

do you think that its better for me to change the textbox that hold the results for another tool?

Is This A Good Question/Topic? 0
  • +

Replies To: Sorting program help

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2271
  • View blog
  • Posts: 9,499
  • Joined: 29-May 08

Re: Sorting program help

Posted 17 June 2008 - 06:57 AM

Quote

Sub BubbleSortNumbers(ByVal iArray As Integer)
	End Sub

	'Selection sort 

	Sub SelectionSortNumbers(ByVal vArray)

	End Sub

	'Shell Sort

	Sub ShellSortNumbers(ByVal vArray)

		Loop Until value = LBound(vArray)
	End Sub
End Class 



The above sub-routines are expecting an integer for input, not an array of integers.

Change vArray as integer
To vArray() as integer

Now The subroutine is expecting an Array of integers.

I hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1