finish rest of code Make sure this program is work Course C
finish rest of code
Make sure this program is work
# Course: CSC 211
# Description: Create a algorithm
#
#
# for (i = 0; i < n-1; i++)
# for (j = i+1; j < n; j++)
# if ( a[i] > a[j])
# swap (a[i], a[j]);
#
#################################################################
jal sort # call the sort subprogram
PROGRAM LOGIC
sort: la $t0,array # t0 = address of a[i]
move $t1,$t0 # t1 = address of a[j]
add $t1,$t1,4
lw $t2,count # t2 = count (i counter)
add $t2,$t2,-1 # t2 = count-1
move $t3,$t2 # t3 = t2 (j counter)
sloop: lw $t4,($t0) # t4 = a[i]
lw $t5,($t1) # t5 = a[j]
ble $t4,$t5,noswap # if (a[i] <= a[j]) do not swap
sw $t4,($t1) # swap a[i] and a[j]
sw $t5,($t0)
noswap: add $t1,$t1,4 # t1 = next address of a[j]
# j count --
# if j count != 0 go back to sort loop
# t0 = next address of a[i]
# i count --
# j count = i count
# if i count = 0 sort is complete
# t1 = the next address of a[i]
# jump to sort loop
endsort:
# return to main procedure
Solution
Implementation of above algorithm in C#:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
int i=0;
int temp=0;
Console.WriteLine(\"Enter the size of array\");
int t = Convert.ToInt32(Console.ReadLine());
int[] arr = new int[t];
for (i = 0; i < t; i++)
arr[i] = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < t - 1; i++)
{
for (int j = i + 1; j < t; j++)
{
if (arr[i] > arr[j])
{
temp=arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
for (i = 0; i < t; i++)
Console.WriteLine(arr[i]);
}
}
}

