Mathematica 9 is now available
Student Support Forum
Student Support Forum: '' topicStudent Support Forum > General > ""

Next Comment >Help | Reply To Topic
Author Comment/Response
09/12/12 10:56pm


Well, I'm having trouble with this code, it's about writing the Selection Sort alghorithm in Mathematica, but inverted, I mean, instead of searching for the smallest number and place it in the first position of a list, I need to search for the biggest one and place it in the last position. I've written this code but as I'm new to Mathematica, I can't find the solution. It doesn't sort the list. Thank you very much for reading, your answers will be helpfull!

L = {};
n = Input["Input the size of the list (a number): "];
For[i = 1, i <= n, m = Input["Input a number to place in the list:"];
L = Append[L, m]; i++]
SelectSort[L] :=
Module[{n = 1, temp, xi = L, j}, While[n <= Length@L, temp = xi[[n]];
For[j = n, j <= Length@L, j++, If[xi[[j]] < temp, temp = xi[[j]]];];
xi[[n ;;]] = {temp}~Join~
Delete[xi[[n ;;]], First@Position[xi[[n ;;]], temp]];

URL: ,

Subject (listing for '')
Author Date Posted
Jose 09/12/12 10:56pm
Re: Bill Simpson 09/14/12 02:52am
Next Comment >Help | Reply To Topic