Implementazioni di algoritmi/Bubble sort: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m Update syntaxhighlight tags - remove use of deprecated <source> tags
Riga 35:
 
=== [[w:linguaggio C++|C++]] ===
<sourcesyntaxhighlight lang="C++">
void BubbleSort(int *array, int elemN)
{
Riga 54:
}
}
</syntaxhighlight>
</source>
''tmp'' è dichiarata di tipo ''int'', quindi dovrà contenere interi; se l'array contiene elementi di tipo diverso, sarà sufficiente modificare la sua dichiarazione.
 
=== [[w:Linguaggio di programmazione Java|Java]] ===
<sourcesyntaxhighlight lang="Java">
public void bubbleSort(int[] x)
{
Riga 77:
}
}
</syntaxhighlight>
</source>
Implementazione dell'algoritmo che presenta le ottimizzazioni enunciate alla voce [[w:Bubble sort|Bubble sort]]:
<sourcesyntaxhighlight lang="Java">
void bubbleSort (int[] a){
boolean swapped=true;
Riga 99:
}
}
</syntaxhighlight>
</source>
Algoritmo implementato sui vector, in questo esempio, di oggetti di tipo String:
<sourcesyntaxhighlight lang="java">
public void bubbleSort(Vector v)
{
Riga 127:
}
 
</syntaxhighlight>
</source>
Segue una documentata implementazione Java dell'algoritmo di sort a bolle,<br>
pensata da uno studente del dipartimento di informatica (ITPS) di Bari:
Riga 159:
* risulta ottimizzato.
*/
<sourcesyntaxhighlight lang="java">
public void sort() {
String temp = "";
Riga 192:
}
 
</syntaxhighlight>
</source>
 
===[[w:Visual Basic .NET|Visual Basic .NET]]===
<sourcesyntaxhighlight lang="vb">
Sub BubbleSort(ByRef MioArray() As Integer)
Riga 208:
 
''MioArray'' sono dichiarati di tipo ''Integer'', quindi dovranno contenere interi; se l'array contiene elementi di tipo diverso, sarà sufficiente modificare le dichiarazioni di entrambi.
</syntaxhighlight>
</source>
 
===[[w:Ruby|Ruby]]===
<sourcesyntaxhighlight lang="ruby">
def bubble(v)
tmp=v.length
Riga 224:
end
end
</syntaxhighlight>
</source>
 
===[[w:Perl|Perl]]===
<sourcesyntaxhighlight lang="perl">
sub bubble_sort(@) {
my @a = @_;
Riga 237:
return @a;
}
</syntaxhighlight>
</source>
 
===[[w:Python|Python]]===
<sourcesyntaxhighlight lang="python">
def bubblesort(iterable):
seq = list(iterable)
Riga 248:
seq[index], seq[index + 1] = seq[index + 1], seq[index]
return seq
</syntaxhighlight>
</source>
 
===[[w:Fortran|Fortran]]===
<sourcesyntaxhighlight lang="fortran">
SUBROUTINE Bubble (X,N)
! X e' l'array da ordinare in modo non decrescente, di estensione N
Riga 268:
END
! GO TO [label] è un'istruzione deprecata da FORTRAN77 e condannata dal Th. di Böhm-Jacopini.
</syntaxhighlight>
</source>
 
===[[w:Lisp|Lisp]]===
<sourcesyntaxhighlight lang="lisp">
(DEFUN bubble-sort (X)
(LET ((Bubble (bubble X)))
Riga 285:
(CONS (CAR X) (bubble (CDR X)))))
(T (ERROR "bubble expects a list"))))
</syntaxhighlight>
</source>
 
===[[w:AppleScript|AppleScript]]===
<sourcesyntaxhighlight lang="Applescript">
on bubblesort( array )
repeat with i from 1 to length of array
Riga 300:
end repeat
end bubblesort
</syntaxhighlight>
</source>
Nota: AppleScript è 1-based, cioè il primo elemento di una lista è 1
 
=== [[w:PHP|PHP]] ===
<sourcesyntaxhighlight lang="PHP">
function bubbleSort ($array)
{
Riga 321:
}
}
</syntaxhighlight>
</source>
 
=== [[w:MATLAB|MATLAB]] ===
<sourcesyntaxhighlight lang="MATLAB">
function vettore = bubblesort(a)
for k=numel(a)-1:-1:1
Riga 337:
end
end
</syntaxhighlight>
</source>
 
== Altri progetti ==