Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Jedno Liberty Basic i bubble sorting pitanje...

[es] :: Art of Programming :: Jedno Liberty Basic i bubble sorting pitanje...

[ Pregleda: 2989 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

gensher
above

Član broj: 68211
Poruke: 74
212.200.180.*



Profil

icon Jedno Liberty Basic i bubble sorting pitanje...27.02.2007. u 17:48 - pre 207 meseci
Bubble sortiranje =>


Za niz

Values(i)= 20 40 30 80 60 90 10 70 50 100

Code:

   For pass = 1 To 10
       For ctr = 1 To 9
          If (Values(ctr) > Values(ctr + 1)) Then
             t = Values(ctr)
             Values(ctr) = Values(ctr + 1)
             Values(ctr + 1) = t
          End If
       Next ctr
    Next pass


Koje vrednosti odgovaraju promenljivim pass od 1 do 10, a koje posebno ctr pri izvrsavanju i zasto ctr od 1 do 9 (to i razumem), ali koje njima vrednosti odgovaraju iz niza?

Kako izvrsava korak po korak kod i koje vrednosti (ili indexe) pri tom koristi?

Hvala
"Anyone who doesn't believe in miracles is not a realist."
-David Ben-Gurion

"Logic will get you from A to B. Imagination will take you everywhere."
"Imagination is more important than knowledge"
Albert Einstein
 
Odgovor na temu

masetrt
Marko Djurovic
Programer, Omni-Explorer
Beograd

Član broj: 3129
Poruke: 228
195.252.119.*

Sajt: www.vast.com


+2 Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 10:40 - pre 207 meseci
Uf pa ovaj kod ti je totalno neispravan. Evo kako bi trebalo da izgleda buble sort:

Code:
For pass = 1 To 9
             For ctr = pass + 1 To 10
                 If (Values(pass) > Values(ctr)) Then
                    t = Values(ctr)
                    Values(ctr) = Values(pass)
                    Values(pass) = t
                 End If
            Next ctr
        Next pass

His majesty Grand Duke of Shumadija and Western Pomoravlje
 
Odgovor na temu

gensher
above

Član broj: 68211
Poruke: 74
212.200.180.*



Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 10:47 - pre 207 meseci
Evo ga zapravo ceo kod

Code:

 Gosub [AskForData]    ' Get user's list of numbers
 Gosub [SortData]      ' Sort the numbers
 Gosub [PrintData]     ' Print the numbers


End

[AskForData]         ' Gets 10 values from the user
   Print "** Number Sorting Program **"
   For i = 1 To 10
       Input "What is a number for the list? "; Value
       Values(i) = Value
   Next i
   Return

[SortData]           ' Sorts the 10 values
   For pass = 1 To 10
       For ctr = 1 To 9
          If (Values(ctr) > Values(ctr + 1)) Then
             t = Values(ctr)
             Values(ctr) = Values(ctr + 1)
             Values(ctr + 1) = t
          End If
       Next ctr
    Next pass
    Return

[PrintData]
    Print
    Print "After the sort:"
    For i = 1 To 10
       Print Values(i); " ";   ' Print list with a space between the
                               ' numbers
    Next i
    Return
End

"Anyone who doesn't believe in miracles is not a realist."
-David Ben-Gurion

"Logic will get you from A to B. Imagination will take you everywhere."
"Imagination is more important than knowledge"
Albert Einstein
 
Odgovor na temu

masetrt
Marko Djurovic
Programer, Omni-Explorer
Beograd

Član broj: 3129
Poruke: 228
195.252.119.*

Sajt: www.vast.com


+2 Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 12:07 - pre 207 meseci
Ok....!? Ne razumem tacno sta si pitao, samo ti onaj algoritam za sortiranje nije tacan. Zameni ga sa onim sto sam ti napisao i sve ce biti OK. Znaci samo deo za sortiranje
His majesty Grand Duke of Shumadija and Western Pomoravlje
 
Odgovor na temu

masetrt
Marko Djurovic
Programer, Omni-Explorer
Beograd

Član broj: 3129
Poruke: 228
195.252.119.*

Sajt: www.vast.com


+2 Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 13:04 - pre 207 meseci
Ups izvini i ono sortiranje sto si ti stavio je tacno :). Mala nepaznja
His majesty Grand Duke of Shumadija and Western Pomoravlje
 
Odgovor na temu

gensher
above

Član broj: 68211
Poruke: 74
212.200.180.*



Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 14:15 - pre 207 meseci
Znaci zanima me kako se tacno izvrsava code korak po korak kroz apsolutne vrednosti izrazeno...

Values(i) = 20 40 30 80 60 90 10 70 50 100

...i koji index kojoj apsolutnoj vrednosti odgovara u podrutini [SortData], ako kaze " pass = 1 To 10 " i " ctr = 1 To 9 ".

Znaci za Values(pass=1) = Values(1) = "neka vrednost" i Values(ctr=1) = Values(1) = "neka vrednost".

Od prilike je to to...

"Anyone who doesn't believe in miracles is not a realist."
-David Ben-Gurion

"Logic will get you from A to B. Imagination will take you everywhere."
"Imagination is more important than knowledge"
Albert Einstein
 
Odgovor na temu

gensher
above

Član broj: 68211
Poruke: 74
212.200.180.*



Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 14:16 - pre 207 meseci
Mislim da imam odgovor na svoje pitanje/a, ali u svakom slucaju zelim da cujem sta ko ima da kaze... Bitno mi je.
"Anyone who doesn't believe in miracles is not a realist."
-David Ben-Gurion

"Logic will get you from A to B. Imagination will take you everywhere."
"Imagination is more important than knowledge"
Albert Einstein
 
Odgovor na temu

masetrt
Marko Djurovic
Programer, Omni-Explorer
Beograd

Član broj: 3129
Poruke: 228
195.252.119.*

Sajt: www.vast.com


+2 Profil

icon Re: Jedno Liberty Basic i bubble sorting pitanje...28.02.2007. u 14:52 - pre 207 meseci
Pazi ovako u sortiranju ti imas ugnjezdene petlje. Znaci prva promenljiva pass ti ide od 1 do 10. E za svaku vrednost pass promenljive imas promenljivu ctr koja ide od 1 do 9 tj. za pass = 1 ctr ti ide od 1 do 9, pa za pass = 2 ctr ti ide od 1 do 9,... Values(1) ti je = 20, Values(2) ti je = 40,...Values(10) ti je = 100. Kad trenutnu vrednost promenljive ctr stavis u Values(ctr) dobices odgovarajuci element niza tj. ako je ctr = 1 onda je Values(ctr) = 20
His majesty Grand Duke of Shumadija and Western Pomoravlje
 
Odgovor na temu

[es] :: Art of Programming :: Jedno Liberty Basic i bubble sorting pitanje...

[ Pregleda: 2989 | Odgovora: 7 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.