import java.util.*;

public class SelectSort
{
    // instance variables - replace the example below with your own
    public int x;
    public ArrayList<Integer> a;
    public int n;
    
    public SelectSort(int b)
    {
        a = new ArrayList<Integer>() ; 
        n = a.size();
        for(int i = 1; i < n; i++)
        {
            SortNow(); //tried everything and the call isn't working

            
        }
    }
    
    private int SortNow(int[] a,int i, int n)
    {
        int small = i;
        for(int j = i; i < n; i++)
        {
            if(a[j] < a[small])
            {
                small = j;
            }
        }
        return small;
    }
}

//I know this looks simple but I'm a beginner :).

Recommended Answers

All 9 Replies

1) Use code Tags
2)SortNow(); // No paramater
3)private int SortNow(int[] a,int i, int n) // Three Paramter

You are calling a function which dont exist...
Pass paramters or make empty paramter function.

public class SelectSort
{
    // instance variables - replace the example below with your own
    public int x;
    public ArrayList<Integer> a;
    public int n;
    
    public SelectSort(int b)
    {
        a = new ArrayList<Integer>() ; 
        n = a.size();
        for(int i = 1; i < n; i++)
        {
            SortNow(int[] w, int n); // says '.Class' expected.
            //Know I stupid but I'm new at this
        }
    }
    
    public int SortNow(int[] a,int i)
    {
        int small = i;
        for(int j = i; i < n; i++)
        {
            if(a[j] < a[small])
            {
                small = j;
            }
        }
        return small;
    }
}
//Don't know what to do

1) Use Code Tags [code] Code here [/code]

2) for(int i = 1; i < n; i++)
{
SortNow(int[] w, int n); 
} 
// dont u know how to pass paramter to function

3) Have u imported java.util.ArrayList; for Array List

4) We all make blunder's when we try new things, it isnt stupidity, that what call learning , but before starting try to read books so you can fully use your brain cells at time of coding.

I already imported arraylist. Thing is sometimes I'm good at this but sometimes I'm absolute rubbish (and this is one of those times.), and you are right my brain cells at this time are dead.

Thanks :). I owe you one.

Very simple solution, get an IDE that error checks. I recommend Eclipse or NetBeans. I personally use Eclipse and threw your code into a new class and it found several errors that have not yet been addressed.

Also one error that eclipse will not catch because it cannot catch Intention errors nor fallacies:

SortNow(int[] w, int n); // several errors, I'll let Eclipse and Google explain them to you.

//Intention error located in piece below, started in the line above

public int SortNow(int[] a,int i) // i initialized to global n
    {
        int small = i; // small initialized to i which = n
        for(int j = i; i < n; i++) // j initialized to i which = n, i = n therefore i will never be < n, newly initialized j ignored and not incremented nor compared to anything so it will always = n
        {
            if(a[j] < a[small]) // never true... j will always = n = small
            {
                small = j; // they already equal one another so...
            }
        }
        return small; // you basically returned n...
    }

IDE dont catch logical errors. Above is a logical error.

commented: Agreed +5

Thanks a lot :), I actually re-wrote the code and worked on it all day. It works better now but I still have a lot to add to it. Thanks for your advice, I'm using BlueJ :P not really the best in the world but sort of forced to use it. Thanks for point out all the mistakes as well :D. I'm a silly programmer hopefully I get better at code :).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.