Hi, can anyone help me please? Using pseudo code, write an algorithm which will input any three different numbers and then print them out in ascending order.
function sort(array) { for (int i = 0; i < 3; i++) { //Check up to array length, start at the first element for(int j= i+1; j < 4; j++) { //Check up to array length + 1, start at the second element. if(a[i] > a[j]) //If the previous element, is greater than the next element in the array, swap it. { temp=a[i]; //Swap variable a[i]=a[j]; a[j]=temp; //Finished swap } } for (int k = 0; k < array.length; k++) { print(a[k]); //Print out the sorted array. } I've written the psuedocode in comments essentially, this is the basic idea. You are swapping elements if they are greater than elements in the array, not sure if you are allowed to use an array or not, but this is a generally accepted solution.
Join our real-time social learning platform and learn together with your friends!