Bubble sort question
Author Message
Bubble sort question

Hi!
I made a bubbleSort like this:
Do
For J = 0 To List1.ListCount - 1
If List1.List(J - 1) > List1.List(J) Then
Temp = List1.List(J - 1)
List1.List(J - 1) = List1.List(J)
List1.List(J) = Temp
Valmis = False
End If
Next J

How can I replace the listbox vwith a Variable?
something like:
Dim XXX(20)

For J = 0 To List1.ListCount - 1
If XXX(J - 1) > XXX(J) Then
Temp = XXX(J - 1)
XXX(J - 1) = XXX(J)
XXX = Temp
Valmis = False
End If
Next J

This does not work.
Thak you!

Fri, 12 Oct 2001 03:00:00 GMT
Bubble sort question
1.
for j = 0 to xxx....
x(j-1) does not exist - runtime error
2. redim xxx(list.listcount)
3. If you sort xxx you need to sort list to?

Do
For J = 0 To List1.ListCount - 1
If List1.List(J - 1) > List1.List(J) Then
Temp = List1.List(J - 1)
List1.List(J - 1) = List1.List(J)
List1.List(J) = Temp
End If
Next J

Quote:

> Hi!
> I made a bubbleSort like this:
> Do
>  For J = 0 To List1.ListCount - 1
>    If List1.List(J - 1) > List1.List(J) Then
>       Temp = List1.List(J - 1)
>       List1.List(J - 1) = List1.List(J)
>       List1.List(J) = Temp
>       Valmis = False
>     End If
>   Next J
> Loop Until Ready = True

> How can I replace the listbox vwith a Variable?
>  something like:
> Dim XXX(20)

>  For J = 0 To List1.ListCount - 1
>    If XXX(J - 1) > XXX(J) Then
>       Temp = XXX(J - 1)
>       XXX(J - 1) = XXX(J)
>       XXX = Temp
>       Valmis = False
>     End If
>   Next J

> This does not work.
> Thak you!

--

Fri, 12 Oct 2001 03:00:00 GMT
Bubble sort question

Quote:

>Hi!
>I made a bubbleSort like this:
>Do
> For J = 0 To List1.ListCount - 1

With J=0, the first iteration attempts to compare List1.List(-1) to
undefined.

Quote:
>   If List1.List(J - 1) > List1.List(J) Then
>      Temp = List1.List(J - 1)
>      List1.List(J - 1) = List1.List(J)
>      List1.List(J) = Temp
>      Valmis = False

I believe the above s/b 'Ready = False'.

Quote:
>    End If
>  Next J

>How can I replace the listbox vwith a Variable?
> something like:
>Dim XXX(20)

> For J = 0 To List1.ListCount - 1
>   If XXX(J - 1) > XXX(J) Then
>      Temp = XXX(J - 1)
>      XXX(J - 1) = XXX(J)
>      XXX = Temp
>      Valmis = False
>    End If
>  Next J

>This does not work.
>Thak you!

Since there are two known reasons why this doesn't work, I'm not surprised
it didn't, but why do you want to replace listbox with a variable?  To save
yourself some typing? It wouldn't save much.  You might want to look into
the 'cutting' and 'pasting' or 'copying' functions available in the editor.

-CB

Fri, 12 Oct 2001 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages