Am I doing this right? (demonstrate TWO sorting algorithms)
Quote:
Create a sortingshowcase class that will demonstrate the use of TWO sorting algorithmsof your choice (from the ones we have covered, namely, selection, bubble andinsertion sort). This class should contain the follow:
· A method for each sortalgorithm being demo’d that receives an unsorted array and modifies the arrayso that it becomes sorted.
· A method to display the elementof an array
· A main method to test that thesorting algorithms are working correctly, i.e. create some sample arrays, printthem before and after the sorting algorithms were called
have to have this done by tomorrow and I'm having trouble understanding fully what I must do, tried fiddling with some code from a sample sheet and came up with this for a simple selection sort, I'f anyone can help me out in regards to properly answering this question fully I would be hugely grateful
Quote:
class sortingshowcase{
for(int x=0; x<n; x++)
{
int index_of_min = x;
for(int y=x; y<n; y++)
{
if(array[index_of_min]>array[y])
{
index_of_min = y;
}
}
int temp = array[x];
array[x] = array[index_of_min];
array[index_of_min] = temp;
}
Re: Am I doing this right? (demonstrate TWO sorting algorithms)
Hello Diizzle,
You seem to be on the right track, but bear in mind the criteria for the general parts you need for this project. As stated in the description you need:
1. A class named sortingshowcase
2. A method for each algorithm (Which is specified as only needing to be 2)
3. A method to display elements of an array
3. A main method which shows that the algorithm methods work.
So far you have #1 down pat. I see no declaration or initialization of the variable n or array for that matter. Is this just sudo code to get the idea down? As-is, this code is not compilable. I would help more, but you haven't asked anything specific which won't help your chances in getting a good response. Also, out of curiosity, what IDE are you using...if any?
Re: Am I doing this right? (demonstrate TWO sorting algorithms)
I'm just using textpad
I have an understanding of what needs to be done, I just can't put it into practice, head is spinning here :/ how should I start?
Re: Am I doing this right? (demonstrate TWO sorting algorithms)
You could start by creating a skeleton of sorts. In this case just get the class created along with the methods inside which would look something like this:
Code Java:
public class testing {
private static void method1() {
// main method code
}
private static void method2() {
// array printing code
}
private static void method3() {
// first algorithm code
}
private static void method4() {
// second algorithm code
}
}
Then focus on one portion at a time.