Hi all, still am having trouble with this i know about arrays, looking for help
ID: 3697951 • Letter: H
Question
Hi all, still am having trouble with this i know about arrays, looking for help in break down how to write in pseudo code by trying to create an array with 20 integer elements, namely array1, array2, array 3, and then I need to pass all three array through sorting methods using bubble sort, selection sort and insertion sort passing all three as arguments. also must count the number of swaps during thes sorting of the two elements for all three sorting methods and at the ened to display the number of swap counts. there is example on here using java, as i don't know java and this introduction programming using the pseudo code and and flow charts. i am having trouble trying construct this together. rather confused. any help using psedu as example using one of the one swap methods to show how construct this would sure help me alot. posted this earlier, i got response back in java code. this introduction to programming and logica class and i have no idea what some the terminalology for java is and help trying to decipher this in to plane starting out with logic and programming and design with no java would help me alot
Explanation / Answer
Arrays: Arrays are containers which contain fixed number of values.
you can declare an array of any datatype like int,char etc.
you have to specify the size of an array and memory is allocated to the array equal to that size.
In java we declare array using
int a[]=new int[10]
where int is the datatype
10 is the size of array and new is used to allocate memory to the array.
Now talking about the sort
Selection sort
Smallest element is selected from the unsorted array and swapped with the leftmost element and that element becomes part of sorted array. This process continues moving unsorted array boundary by one element to the right.
so for example suppose our unsorted array is
10 5 4 2 88 34 23 1 9
now we will find the minimum element in the array which is 1 and swap it with leftmost element in unsorted array i.e 10
so array becomes 1 5 4 2 88 34 23 10 9
now 1 element is in its correct position but remaining array is unsorted so we will do the same for remaining unsorted array
in 5 4 2 88 34 23 10 9 min is 2 and leftmost element is 5 so we will swap them and now array becomes
1 2 4 5 88 34 23 10 9
so first two elements are sorted and rest of the array is unsorted.
Same process is continued to sort the array.
We can keep a varibale and every time a swap occurs in sort we will increment the variable to keep the count of number of swaps
Now if you have any questions comment on the answer
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.