 |
CowBoy |
[Bubblesort vs. Quicksort] Bellissimo!! |
15-02-2011 17:34 |
|
 |
CowBoy |
.arcimaestro.
Registered: May 2006
Posts: 294 (0.04 al dì)
Location: Milano
Corso: F49 - Informatica
Anno: Laureato F49
Time Online: 3 Days, 13:40:27 [...]
Status: Offline
Edit | Report | IP: Logged |
[Bubblesort vs. Quicksort] Bellissimo!!
Che la sfida abbia inizio:
http://www.youtube.com/watch?v=vxENKlcs2Tw
__________________
.. ±·ø·±-`` MuSiC iS My LanGuAGe ´´-±·ø·± ..
|
15-02-2011 17:34 |
|
|
|  |
 |
xSharKMaNx |
[url]http://www.geek.com/articles/geek-cetera/sort ... |
15-02-2011 19:47 |
|
 |
xSharKMaNx |
un gioco della follia

Registered: Sep 2007
Posts: 1477 (0.23 al dì)
Location:
Corso: F49
Anno: Laureato
Time Online: 10 Days, 17:15:29 [...]
Status: Offline
Edit | Report | IP: Logged |
http://www.geek.com/articles/geek-c...fects-20100819/
Buona visione 
__________________
Perché, mentre il manganello può sostituire il dialogo, le parole non perderanno mai il loro potere; perché esse sono il mezzo per giungere al significato, e per coloro che vorranno ascoltare, all'affermazione della verità. E la verità è che c'è qualcosa di terribilmente marcio in questo paese. (V)
I popoli non dovrebbero aver paura dei propri governi, sono i governi che dovrebbero aver paura dei popoli. (T.J)
|
15-02-2011 19:47 |
|
|
|  |
 |
CowBoy |
Dubbio quicksort |
15-02-2011 21:17 |
|
 |
CowBoy |
.arcimaestro.
Registered: May 2006
Posts: 294 (0.04 al dì)
Location: Milano
Corso: F49 - Informatica
Anno: Laureato F49
Time Online: 3 Days, 13:40:27 [...]
Status: Offline
Edit | Report | IP: Logged |
Dubbio quicksort
Ho scritto l'algoritmo quicksort in VBA secondo le indicazioni trovate nella dispensa di Goldwurm, poiché svolgendo i calcoli a mano non riuscivo ad ordinare la sequenza in modo corretto.
L'array viene rappresentato dalla colonna A(A[1], A[2]... A[n]), contenente in celle consecutive una sequenza di numeri da ordinare. La pila viene rappresentata dalle colonne C e D.
Provo ad eseguire l'algoritmo e nella maggior parte delle volte la sequenza non è ordinata... sapete dirmi dove sto sbagliando?
HO RISOLTO!!! IL CODICE ADESSO FUNZIONA
code:
Function partition(ByVal p As Integer, ByVal q As Integer) As Integer
Dim i As Integer
Dim j As Integer
i = p + 1
j = q
While (i <= j)
While (Cells(j, 1) > Cells(p, 1))
j = j - 1
Wend
While ((Cells(i, 1) <= Cells(p, 1)) And i <= j)
i = i + 1
Wend
If i < j Then
scambia i, j
i = i + 1
j = j - 1
End If
Wend
scambia p, j
partition = j
End Function
Function scambia(ByVal p As Integer, ByVal q As Integer)
Dim t As Integer
t = Cells(p, 1)
Cells(p, 1) = Cells(q, 1)
Cells(q, 1) = t
End Function
Function random(ByVal a As Integer, ByVal b As Integer) As Integer
random = a + Rnd * (b - a)
End Function
Function quicksort(ByVal a As Integer, ByVal b As Integer)
Dim p As Integer
Dim q As Integer
Dim k As Integer
Dim l As Integer
Dim x As Integer ' pila
Dim s As Integer ' stop
Dim i As Integer
Dim j As Integer
p = a
q = b
x = 0
s = 0
Do
While p < q
k = random(p, q)
scambia p, k
l = partition(p, q)
If l - p < q - l Then
i = l + 1
j = q
q = l - 1
Else
i = p
j = l - 1
p = l + 1
End If
x = x + 1
Cells(x, 3) = i
Cells(x, 4) = j
Wend
If x <> 0 Then
p = Cells(x, 3)
q = Cells(x, 4)
x = x - 1
Else
s = 1
End If
Loop While (s = 0)
End Function
Sub exec()
quicksort 1, Application.WorksheetFunction.Count(Range("A:A")) ' quicksort da 1 a n
End Sub
Potete provarlo sul foglio di lavoro nel post successivo...
__________________
.. ±·ø·±-`` MuSiC iS My LanGuAGe ´´-±·ø·± ..
Last edited by CowBoy on 16-02-2011 at 04:33
|
15-02-2011 21:17 |
|
|
|  |
 |
CowBoy |
Worksheet: ... |
15-02-2011 21:22 |
|
 |
CowBoy |
.arcimaestro.
Registered: May 2006
Posts: 294 (0.04 al dì)
Location: Milano
Corso: F49 - Informatica
Anno: Laureato F49
Time Online: 3 Days, 13:40:27 [...]
Status: Offline
Edit | Report | IP: Logged |
Worksheet:
Attachment: quicksort.rar
This has been downloaded 4 time(s).
__________________
.. ±·ø·±-`` MuSiC iS My LanGuAGe ´´-±·ø·± ..
Last edited by CowBoy on 16-02-2011 at 04:41
|
15-02-2011 21:22 |
|
|
|  |
 |
All times are GMT. The time now is 09:41. |
|
|
 |
|
 |
|
|
|  |
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
|
|
|
|
|
|