Question

Create MIPS program that sorts positive numbers. Inputs the numbers until a zero is inputted and the program displays the sorted numbers. Can use any sorting algorithm except bubble sort.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable Matlab Code:

% Input the number of elemnts to be sorted
num=input('Enter the number of numbers to be sorted: ');

% Create an array
arr=[];

% Input numbers to the array
for i=1:num
% Input the numbers
arr(i)=input('Enter the number: ');
end

% For each pass
for j=1:1:num-1
  
%Compare adjacent elements
for i=1:1:num-1
  
% If adjacenet elements in wrong order
if arr(i)>arr(i+1);
  
% Swap the elemnts
tem=arr(i);
arr(i)=arr(i+1);
arr(i+1)=tem;
end
end
end

% Output the array
fprintf('The elements in ascending order given below:\n')
disp(arr)


answered by: ANURANJAN SARSAM
Add a comment
Know the answer?
Add Answer to:
Create MIPS program that sorts positive numbers. Inputs the numbers until a zero is inputted and the program displays the sorted numbers. Can use any sorting algorithm except bubble sort.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create MIPS program that sorts positive numbers. Inputs the numbers until a zero is inputted and the program displays the sorted numbers. Can use any sorting algorithm except bubble sort.

    Write a MIPS assembly program that sorts a sequence of positive integersentered from the console (one number in one line). The end of thesequence is indicated by a 0 (zero). Verify that the program is correct bysimulation. You can use any sorting algorithm in your code except bubblesort, such as selection sort, merge sort, quick sort, etc. There must be aprocedure call as well as looping in your code. use recursive procedurecalls instead of looping to solve the same problem....

  • Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers

    Write a program in MIPS assembly language that implements the DESCENDING bubble sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • MIPS insertion sort program......could really use some assistance

    Write a program in MIPS assembly language that implements the DESCENDING insertion sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • MIPS insertion sort program......could really use some assistance

    Write a program in MIPS assembly language that implements the DESCENDING insertion sort algorithm to sort a variable-sized array of signed 32-bit integers (words)that are read from the console. Be reminded that in a descending sort, the integers are sorted from the largest to the smallest. A “special value” 99999 will beused to signify the end of the input sequence. This value is not to be considered part of the input data set. However, any value greater than 99999 that...

  • C++ SORTING – BUBBLE SORT METHOD Use the below Text File and write code that sorts...

    C++ SORTING – BUBBLE SORT METHOD Use the below Text File and write code that sorts it based on the users sort method selection. Please provide a separate .cpp file wit hthe code containing the sort method. The sorting method uses the text file below and sorts it accordingly. Seperate the sorting method into an additional C++ file. ********************************* Text File Below is a text file called classes.txt. This text file lists, by course number and section number a series...

  • does anyone know how to do this? C++ Your task for this assignment is to use...

    does anyone know how to do this? C++ Your task for this assignment is to use C++ language to implement an insertion sort algorithm. 1. Implement an insertion sort with an array to sort 10 arbitrary numbers using the C++ programming language. The program initializes an array with 10 random 3-digit positive integers. The program then sorts the numbers in the array using the insertion sort algorithm. 2. The program displays the original values in the array before the sort...

  • Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template...

    Objective: 1. Understand sorting algorithm 2. Implement bubble sort in C++ Check slides for a template of the solution, if you need Write a program that asks users to input 10 integers into an array, write a function that takes the array as its argument, use bubble sort to sort the array and output the sorted array in increasing order. #include <iostream> using namespace std; C:IWINDOWSSystems2cmd.exe lease input 10 integers: void bubblesort(int a[10]) int help; int b[10]; for (int i...

  • You will create a dimple Bubble Sort program to sort a string of random integers or...

    You will create a dimple Bubble Sort program to sort a string of random integers or text. Please read instructions and examples Please show screenshot of proof that the code works in the C program ECE 216 Programming Project 2 The Bubble Sort You will create a simple Bubble Sort program to sort a string of random integers or text or whatever you can punch in from the keyboard. For the input data, you will input a string of single...

  • Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. E...

    Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...

  • in C please 20. Change the bubble sort algorithm (Program 12-5) as follows: Use two directional...

    in C please 20. Change the bubble sort algorithm (Program 12-5) as follows: Use two directional bubbling in each pass. In the first bubbling, the smallest ele. ment is bubbled up; in the second bubbling, the largest element is bubbled I down. This sort is known as the shaker sort. 12-5 Bubble Sort (continued) // Statements // Each iteration is one sort pass for (int current = 0, sorted = 0; current <= last && !sorted; current++) for (int walker...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT