Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Am I doing this right? (demonstrate TWO sorting algorithms)

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Am I doing this right? (demonstrate TWO sorting algorithms)

    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

    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;

    }


  2. #2
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default 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?
    Last edited by KucerakJM; March 26th, 2012 at 12:51 AM. Reason: Stupidity

  3. The Following User Says Thank You to KucerakJM For This Useful Post:

    Diizzle (March 26th, 2012)

  4. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default 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?

  5. #4
    Member
    Join Date
    Mar 2012
    Location
    United States
    Posts
    118
    My Mood
    Inspired
    Thanks
    1
    Thanked 33 Times in 31 Posts

    Default 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:
    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.

  6. The Following User Says Thank You to KucerakJM For This Useful Post:

    Diizzle (March 26th, 2012)

Similar Threads

  1. SORTING ALGORITHMS...
    By Medo Almasry in forum Algorithms & Recursion
    Replies: 3
    Last Post: October 14th, 2011, 08:18 PM
  2. Re: Sorting Algorithms
    By shashiwagh in forum Java Theory & Questions
    Replies: 1
    Last Post: March 23rd, 2011, 02:19 PM
  3. Sorting Algorithms
    By Dalisra in forum Java Programming Tutorials
    Replies: 1
    Last Post: November 10th, 2009, 09:24 PM
  4. Sorting Algorithms
    By Dalisra in forum Java Code Snippets and Tutorials
    Replies: 1
    Last Post: November 10th, 2009, 09:24 PM
  5. Java algorithm for bank program to connect database
    By araujo3rd in forum Algorithms & Recursion
    Replies: 1
    Last Post: December 10th, 2008, 01:34 PM