I'm trying to write this algorithm with tail recursion in Scala.
public ArrayList sort(ArrayList<int> toSort)
{
ArrayList<int> list=toSort;
for(int i=0; i<list.size();i++)
{ int min=100;
int pos=-1;
for(int j=i+1; j<list.size();j++)
{
if(list.get(i)>list.get(j) && list.get(j)<min)
{
min=list.get(j);
pos=j;
}
}
if(pos!=-1)
{
int a=list.get(i);
list.set(i,list.get(pos));
list.set(pos,a);
}
}
return list;
}
I'm new in Scala and functional programming so I don't know very well how to code that. can anybody help me with some ideas?
Thank you very much in advance