Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Sorting numbers is a very common problem: here, you just have 3 numbers to sort.

ID: 3803016 • Letter: S

Question

Sorting numbers is a very common problem: here, you just have 3 numbers to sort. This MIPS/SPIM program includes a subroutine called my add that performs x = (y + z); In the space below, replace the myadd subroutine with one named my sort that will sort the values of x, y and z and into increasing order (i.e., make x the smallest and z the largest). You should test your routine using SPIM before program but only submit the mysort routine here. #### # # Addition routine: # x = y + z # .text .globl myadd myadd la $t0, # t0 = y lw $t0,0($t0) la $t 1, z #t1 = z lw $t1,0($t1) addu $t2, $t0, $t1. # t2 = y + z la $t0, x # x = t2 SW $t2,0($t0) jr $ra # return

Explanation / Answer

class SortDemo
{
static int y=3,z=2;
public static void main(String k[])
{
   SortDemo demo = new SortDemo();
   int x = demo.myAdd(y,z);
   demo.mySort(x,y,z);
}
public int myAdd(int y, int z)
{
   int x = y+z;
   return x;
}

public void mySort(int x, int y, int z)
{
   if(x > y && x > z)
   {
   System.out.println("X is greatest = "+x);
   if(y > z)
   {
   System.out.println("Y is second greatest = "+y);
   System.out.println("Z is smallest = "+z);
   }
   else
   {
   System.out.println("z is second greatest = "+z);
   System.out.println("y is smallest = "+y);
   }
   }
   else
   {
   System.out.println("X is smallest = "+x);
   if(y > z)
   {
   System.out.println("Y is second greatest = "+y);
   System.out.println("Z is smallest = "+z);
   }
   else
   {
   System.out.println("z is second greatest = "+z);
   System.out.println("y is smallest = "+y);
   }
   }
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote