zielo icon

Sortowanie bąbelkowe

zielo | PRO | 04/20/18 11:25:14 PM UTC | 0 ⭐ | 7793 👁️ | Never ⏰ | []
Octave |

790 B

|

None

|

0 👍

/

0 👎

N = 80;
rand_tab = rand(1,N)*20-10; #zapełniam wektor rand_tab warościami losowymi w przedziale [-10,10]
#rand_tab = sort(rand_tab);
x = 1:N; #zakres x na wykresie
#plot(x,rand_tab(x),"."); #wykres
rand_tab_d = rand_tab(rand_tab>=0); #tworzę nowy wektor z warości nieujemnych
rand_tab_d1 = rand_tab_d; #tworzę kopię tablicy
#sortowanie bąbelkowe
n = length(rand_tab_d);
x = 1:n;
 #    plot(x,rand_tab_d(x),"b.");
for i=1:(n-1)
  for j=1:n-i
    if (rand_tab_d(j) > rand_tab_d(j+1)) 
      z = rand_tab_d(j);
      rand_tab_d(j) = rand_tab_d(j+1);
      rand_tab_d(j+1) = z;
 #     drawnow;
         hold on; 
         cla;
          plot(x,rand_tab_d(x),"bo");
        pause(0.1);
#      hold off;
    endif
 
  endfor
endfor
#x = 1:n;
#plot(x,rand_tab_d(x),"b."); #wykres

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎