You are on page 1of 6

6.

)BUBBLE SORT
input v,n;
repeat
ok:= true;
for i:=1 to n-1 do
if v[i]>v[i+1] then
ok:=false;
aux:=v[i];
v[i]:=v[i+1];
v[i+1]:=aux;
endif;
endfor;
until ok;
end.

Quick sort
quicksort(v,st,dr);
pivot:=v[(st+dr) div 2)]
while i<=j do
while v[i] < pivot do
i:=i+1;
if i<=j then
aux:=v[i];
v[i]:=v[j];
v[j]:=aux;
i:=i+1;
j:=j+1;
if st<j then
quikSort(v,st,j);
if i<dr atunci
quikSort(v,i,dr)

determine all the


8.)prime numbers to a value n

input n;
nr:=0;x:=2;
while nr<n do
K:=true;
for d:=2 to x div 2 do
if x mod d=0 then k:=false;
if k=true then
nr:=nr+1;
output(x);
endif;
endif;
endfor;
endwhile;

You might also like