gaza165 Posted November 27, 2008 Share Posted November 27, 2008 void setup() { int i; String OutPutLine = ""; PFont font; String[] Strs; int Size; int[] Nums; int Sum; font = loadFont("Calibri-48.vlw"); textFont(font); background(255, 255, 0); fill(0, 0, 0); Strs = loadStrings("Input.txt"); Size = Strs.length; size(800,800); Nums = new int[size]; for (i = 0; i < Size; i++) { Nums[i] = int(Strs[i]); } PrintArray(Nums,20); PrintArray(SortArray(Nums),50); } void PrintArray(int[] Vals, int Down) { int i; int L = Vals.length; String OutPutLine = ""; for (i = 0; i < L; i++) { OutPutLine += str(Vals[i]) + ","; } text(OutPutLine,10,Down * 3); } // PRE TRUE // POST RETURNS array whose elements are those of // Nums sorted into ascending order int[] SortArray(int[] Nums) { int i, j; int Size = Nums.length; int Next; for (i = 1; i < Size; i++) { Next = Nums[i]; for (j = i - 1; (j >= 0) && (Nums[j] > Next); j--) { Nums[j + 1] = Nums[j]; } Nums[j + 1] = Next; } return(Nums); } i have an array of numbers from a text file... i have to write methods to print out these numbers in ascending, descending and write them to text files. 23, 41, 3, 56, 42, 9, 82, 56, 29 3,9,23,29,41,42,56,56,82 i can do this but then i need it to do 29,56,82,9,42,56,3,41,23 - so the reverse of its orginal form..... can someone help me to write my method??? Thanks Link to comment https://forums.phpfreaks.com/topic/134539-processing-10-beta/ Share on other sites More sharing options...
corbin Posted November 28, 2008 Share Posted November 28, 2008 Just mod PrintArray to do it backwards: void PrintArray(int[] Vals, int Down) { int i; int L = Vals.length; String OutPutLine = ""; for (i = L; i > 0; --i) { OutPutLine += str(Vals[i]) + ","; } text(OutPutLine,10,Down * 3); } Link to comment https://forums.phpfreaks.com/topic/134539-processing-10-beta/#findComment-700840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.