Visual Basic - Range Variable Visual Basic

Life is soft - evento anual de software empresarial
 
Vista:

Range Variable Visual Basic

Publicado por catherine (1 intervención) el 14/04/2014 20:22:12
I need to program Counting Sort (increasing order) on Visual Basic. So far, I have managed to program it using an array of numbers (serie ()) but I need to give in the numbers using the variable Range (serie as Range). Any ideas on how to change it?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
Function ordenarCuentas(serie() As Integer) As Long()
 
Dim posicion As Long
Dim cuentas() As Long
Dim serieOrdenada() As Long
Dim minimo As Integer
Dim maximo As Integer
 
minimo = serie(0)
maximo = serie(0)
 
For posicion = 1 To UBound(serie)
    If serie(posicion) > maximo Then
        maximo = serie(posicion)
 
    Else
        If serie(posicion) < minimo Then
            minimo = serie(posicion)
        End If
    End If
Next
 
ReDim cuentas(0 To maximo - minimo)
 
For posicion = 0 To maximo - minimo
    cuentas(posicion) = 0
Next
 
For posicion = 0 To UBound(serie)
    cuentas(serie(posicion) - minimo) = cuentas(serie(posicion) - minimo) + 1
Next
 
cuentas(UBound(cuentas)) = UBound(serie) - cuentas(UBound(cuentas)) + 1
 
For posicion = UBound(cuentas) - 1 To 0 Step -1
    cuentas(posicion) = cuentas(posicion + 1) - cuentas(posicion)
Next
 
 
ReDim serieOrdenada(0 To UBound(serie))
 
For posicion = 0 To UBound(serie)
    serieOrdenada(cuentas(serie(posicion) - minimo)) = serie(posicion)
    cuentas(serie(posicion) - minimo) = cuentas(serie(posicion) - minimo) + 1
Next
 
ordenarCuentas = serieOrdenada()
 
End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder