Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

2D array sort using function

salletkdsalletkd Posts: 5Member
Hi. I've started programming recently so I'm a newbie. I checked how functions work, and tried to sort 2D array using function. Here's the code:
[code]

program functionSort;
uses crt;
var a:array of integer;
i,j:integer;

function sort(a:array of integer):array of integer;
var i,j,k,l,tmp:integer;
begin
for i:=1 to 3 do
for j:=1 to 2 do
for k:=1 to 3 do
for l:=1 to 2 do
begin
if a[i,j]>a[k,l] then
begin
tmp:=a[i,j];
a[i,j]:=a[k,l];
a[k,l]:=tmp;
end;
end;
sort:=a;
end;


begin
for i:=1 to 3 do
for j:=1 to 2 do
begin
read(a[i,j]);
end;
write('Press anykey');
readkey;
for i:=1 to 3 do
for j:=1 to 2 do
begin
writeln(sort(a));
end;
readkey;
end.
[/code]
Another question, what's this sort called? Bubblesort or Selection sort? Or something third?
Sign In or Register to comment.