Note why Roger's picture looked different:
this algorithm uses recursion and we only captured
the tail of it, so the resulting heads were those items
disapearing from previous step.
Here's fully captured steps.
cap=: [ 3 : 'A=:A,<y'
A=: ''
(([EMAIL PROTECTED] , ($:@#~ -.)) (= <./))@cap ^: (1<#) C
0 0 2 4 4 5 6 7 9 9
view }:,~&>/ 7({. ,: a:,(<@;\@|[EMAIL PROTECTED])) A
+---------+---------+---------+---------+---------+---------+---------+
|****** | | | | | | |
|***** | | | | | | |
|*********|****** |** |** |** |** |** |
|** |***** |****** |**** |**** |**** |**** |
|**** |*********|***** |**** |**** |**** |**** |
|*********|** |*********|****** |***** |***** |***** |
| |**** |**** |***** |****** |****** |****** |
|******* |*********|*********|*********|*********|*********|******* |
| |******* |******* |*********|*********|*********|*********|
|**** |**** |**** |******* |******* |******* |*********|
+---------+---------+---------+---------+---------+---------+---------+
--- On Mon, 4/28/08, Oleg Kobchenko <[EMAIL PROTECTED]> wrote:
> > ----- Original Message ----
> >
> > From: Björn Helgason <[EMAIL PROTECTED]>
> > Bubblesort is fun
> > If you have lots of lines and use only 0 and 1 it
> flows
> > like bubbles to the
> > top.
> > Show the results after each trip and wait a second
Here's visualization of different algorithms, which
shows their behavior and how they compare to bubble sort.
http://en.wikipedia.org/wiki/Sorting_algorithm
Roger's solution is close to "Selection sort".
Whereas in Raul's they are bubbling in parallel
(I am not sure which one it corresponds to).
view=: '*' <@:(#~"0)"1 ]
view ((,~`,@.< [EMAIL PROTECTED]) , [EMAIL PROTECTED])/^:a: C
NB. Oleg's original
+---------+---------+---------+---------+---------+---------+---------+
|****** | | | | | | |
|***** |****** | | | | | |
|*********|***** |****** |** |** |** |** |
|** |*********|***** |****** |**** |**** |**** |
|**** |** |*********|***** |****** |**** |**** |
|*********|**** |** |*********|***** |****** |***** |
| |*********|**** |**** |*********|***** |****** |
|******* | |*********|**** |**** |*********|******* |
| |******* |**** |*********|******* |******* |*********|
|**** |**** |******* |******* |*********|*********|*********|
+---------+---------+---------+---------+---------+---------+---------+
repair=: C.~ _2&(({. > {:)\ # (<\ [EMAIL PROTECTED])) NB. Raul
1
bubsort=: repair @ ({. , [EMAIL PROTECTED])
view bubsort^:a: C
+---------+---------+---------+---------+---------+
|****** |***** |** | | |
|***** |****** |***** |** | |
|*********|** | | |** |
|** |*********|****** |***** |**** |
|**** | | |**** |**** |
|*********|**** |*********|****** |***** |
| | |**** |**** |****** |
|******* |*********|**** |*********|******* |
| |**** |******* |******* |*********|
|**** |******* |*********|*********|*********|
+---------+---------+---------+---------+---------+
'*' <@:(#~"0)"1 (A.~ [EMAIL PROTECTED]@# +/ .* 0 , 2 </\ |.)^:a: C NB. Raul
2
+---------+---------+---------+---------+---------+---------+---------+---------+
|****** |***** |***** |** |** |** | |
|
|***** |****** |** |***** |**** | |** |
|
|*********|** |****** |**** | |**** | |**
|
|** |*********|**** | |***** | |**** |****
|
|**** |**** | |****** | |***** |**** |****
|
|*********| |*********| |****** |**** |***** |*****
|
| |*********| |*********|**** |****** |****** |******
|
|******* | |*********|**** |*********|******* |******* |*******
|
| |******* |**** |*********|*******
|*********|*********|*********|
|**** |**** |******* |*******
|*********|*********|*********|*********|
+---------+---------+---------+---------+---------+---------+---------+---------+
A=: ''
((#~ , ($:@#~ -.)) (= <./))@([3 :'A=:A,<y') ^: (1<#) C NB. Roger's solution
0 0 2 4 4 5 6 7 9 9
view _10{.&>A
+---------+---------+---------+---------+---------+---------+---------+
|****** | | | | | | |
|***** | | | | | | |
|*********|****** | | | | | |
|** |***** |****** | | | | |
|**** |*********|***** | | | | |
|*********|** |*********|****** | | | |
| |**** |**** |***** |****** | | |
|******* |*********|*********|*********|*********|*********| |
| |******* |******* |*********|*********|*********|*********|
|**** |**** |**** |******* |******* |******* |*********|
+---------+---------+---------+---------+---------+---------+---------+
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now.
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm