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

use lc-3 Write a selection sort for sorting the n 16-bit data items stored in th

ID: 3802620 • Letter: U

Question

use lc-3 Write a selection sort for sorting the n 16-bit data items stored in the array Data in ascending order. Declare two labels n and Data to hold the # of data items and the actual data to be sorted respectively. You may assume that the data values to be sorted are between 0 and 127. Before performing the sort, print the data elements, treating each as an ASCII character. Once the data has been sorted, print the contents of the array (no special formatting required), treating each element as an ASCII character. To test your program, use the following test case:

n .fill 14

data

.fill x7B

.fill x3F

.fill x6E

.fill x30

.fill x2A

.fill x5E

.fill x38

.fill x69

.fill x5C

.fill x60

.fill x34

.fill x5A

.fill x20

.fill x2A

Explanation / Answer

Selection Sort

1. Select the smallest unsorted item and then swap it with the next postion item to be filled.
2. Logic: The Smallest element is searched in the enitre array , once it is found, swap it (the smallest element)
   with the first element of the array. Continue this process and then look for the smallest element
   in the remaining array and swap it with the second element.

public void selectionSortalgorithm(){

int []ar;
//write an array and fill it with the elements from 0 to 127
for(int k=0;k<=127;k++)
{
   ar[k]=k;
}
for (int index = 0; index ‹ ar.length-1; index ++)
{
int minimum = index ;
for (int j = index +1; j ‹ ar.length; j++)
if (ar[j] ‹ ar[minimum])
minimum = j;
int temp = ar[i];
ar[i] = ar[minimum];
ar[minimum] = temp;
} }

It will perform the sorting