Write a program that inputs ten (10) integers and then sorts them in order from largest to smallest in the programming language called Perl. You do not need to error check the input; you can assume the user enters integers. You can select the sorting algorithm of your choice, but you must implement this algorithm yourself. You cannot use a built-in sorting function. [15 points]
Below is an example of a sample program run:
Unsorted: 10, 4, 23, 99, 7, 2, 1, 11, 44, 15
Sorted: 99, 44, 23, 15, 11, 10, 7, 4, 2, 1
Algorithm
1.Declare Ascending and Descending order two arrays .
2. find out min and max integer from original array
3.Put them at start of new array
4.remove them from original arrays
5.Repeat step 2.
6.finish the algorithm.
###############################
Warning:-Please remove all comments from the code and maintain proper indentation to run the code on your own compiler.
Code:-
#!/usr/bin/perl
use strict;use warnings;
my @tab = qw//; #Declaration of Array
for (1 .. 10) {
my $num = <STDIN>; #TAking array as input
chomp $num;
push @tab, $num;
}
my ($n,$max,@tri,@tri_desc); #Declaration of ascending and descending order Arrays.
$max = $tab[0];
print "@tab\n";
while(@tab){ #Sorting begins here
$_ > $max and $max = $_ for @tab;
for (@tab){ $n++;last if $max == $_}
unshift @tri,$max;
push @tri_desc,$max;
splice(@tab,$n-1,1);
$n=0;
$max = $tab[0];
}
print "ascending order:\t@tri\n";
print "descending order:\t@tri_desc\n";
############################################################
Write a program that inputs ten (10) integers and then sorts them in order from largest...
write a program in x86 assembly language that sorts 10 integers entered from the keyboard and displays them in order
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. Please use mips language not C or C++ or any other languages except mips.
DESCRIPTION Implement a program in C++ that generates a specified number of random integers, records them in three arrays, then sorts the arrays with Insertion Sort, Merge Sort, and Quick Sort, respectively. Augment the three sorting algorithms with counters and report the number of characteristic operations each performs in sorting the (same) random values. INPUT The program reads from the terminal the number of random integers to generate, a seed value for the pseudo-random number generator, and a character that...
Question 5 (10 Points) Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection-Sort segments the list into sorted and unsorted elements. The algorithm continues to remove the smallest element of the unsorted list and adds it to the sorted segment. Implement the algorithm that accepts an unsorted list and returns a sorted one - in ascending order. 5 3 8 Initial List 4 6 18 4 6 Minimum Swaps Position: Sorted List Length 1 Minimum Swaps Position:...
please help with python Write a well-documented, Python program, hmwk305.py that implements the Selection-Sort algorithm. Selection Sort segments the list into sorted and unsorted elements. The algorithm continues to remove the smallest element of the unsorted list and adds it to the sorted segment. Implement the algorithm that accepts an unsorted list and returns a sorted one - in ascending order. 5 3 8 4 6 Initial List Minimum Swaps Position: Sorted List Length 1 Minimum Swaps Position: Sorted List...
Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sublist using a sorting algorithm of your choice. The two sublists are then merged by a third thread—a merging thread —which merges the two sublists into a single sorted list. Because global data are shared cross all threads, perhaps the easiest way to set up the data...
For C++ Write a program that randomly generates 100 integers and sorts them using radix sort. Note: Your output would not be the same as this sample output due to the randomness. Sample output: 0 0 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 4 5 5 5 6 6 6 6 6 6 7 7 7 7 7 7...
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...
Write a program in python that generates X random integers Num. Num is a random number between 20 to 50. X is a random number between 10 to 15. Calculate and show the Smallest, Largest, Sum, and Average of those numbers. You are not allowed to use Python functions sample(), min(), max(), average(), sort(), sorted()!! HINTs: to find Smallest.... 1) X is a random number between 10 to 15... for example 11...this determines how many times the loop will happen...
4.12 LAB: Smallest number Write a program whose inputs are three integers, and whose output is the smallest of the three values. Ex: If the input is: 7 15 3 the output is: 3 I have to write this in python, having a hard time deciding how to approach this. Thank you!