changed=true do while changed changed=false for i=lbound(d) to ubound(d)-1 if d(i)>d(i+1) then tmp=d(i):d(i)=d(i+1):d(i+1)=tmp changed=true end if next loop
for i=lbound(d) to ubound(d) response.write d(i) & "<br>" next %>
Det forstår jeg ikke du sikker på de dubletter ikke er der to gange i arrayet?
Alternativt så prøv denne:
A = Split("david,pedersen,anders,ost", ",")
gap = ubound(A) OK = True While OK 'You can try other values, but 1.33 seems to be the best gap= Int(gap/1.33) If gap < 1 Then gap = 1 OK = (gap <> 1) For i = 0 To M - gap j = i + gap If A(i) > A(j) Then x = A(i) A(i) = A(j) A(j) = x OK = True End If Next Wend
M=ubound(A) gap = M OK = True While OK 'You can try other values, but 1.33 seems to be the best gap= Int(gap/1.33) If gap < 1 Then gap = 1 OK = (gap <> 1) For i = 0 To M - gap j = i + gap If A(i) > A(j) Then x = A(i) A(i) = A(j) A(j) = x OK = True End If Next Wend
Man kan lave det når man har strengen med teksten før sorteringen sådan her:
str = "david,david,pedersen,anders,ost" arr = Split(str,",") tmp = "," for i = lbound(arr) to ubound(arr) if inStr(1,tmp,","&arr(i)&",",1) = 0 then tmp = tmp & arr(i) & "," next str = mid(tmp,2,len(tmp)-2)
'Sorter her A = Split(str, ",")
M=ubound(A) gap = M OK = True While OK 'You can try other values, but 1.33 seems to be the best gap= Int(gap/1.33) If gap < 1 Then gap = 1 OK = (gap <> 1) For i = 0 To M - gap j = i + gap If A(i) > A(j) Then x = A(i) A(i) = A(j) A(j) = x OK = True End If Next Wend
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.