Java Solve Java Selection Sort Issues | Hi, I'm Working on Code

  • Thread starter Thread starter tshet
  • Start date Start date
  • Tags Tags
    Java Sort
AI Thread Summary
The discussion revolves around issues encountered while implementing selection sort in Java. The user shares their code, which is intended to sort an array but fails to compile due to several errors. Key problems identified include the incorrect use of the array variable 'a', which is not properly initialized or referenced, leading to compilation issues. The user acknowledges that they based their selection sort structure on a bubble sort implementation, indicating a potential misunderstanding of the selection sort algorithm. Other participants emphasize the importance of providing specific error messages from the compiler to diagnose the issues effectively. They suggest that without clear indications of the errors, it's challenging to provide accurate assistance. The conversation highlights the need for clarity in coding practices and debugging processes.
tshet
Messages
2
Reaction score
0
Hi, I'm currently working on my selection sort code, and I've come across some problems.

Java:
i
import java.util.Arrays;
import java.io.*;

public class SelectionSort
{
int a[];
static int n;

public static void main(String[] args)
{
int array[] = { 5,3,9,7,1,8 };
n = 6;
System.out.println(""+Arrays.toString(Sort(array)));
}

public static int[] Sort(int[] arr)
{
int t, min;
for(int i=0;i<n-1;i++)
{
min = i;
for(int j=i+1;j<n;j++)
{
if(a[min]>a[j])
min = j;
}
if(min!=i)
{
t = a[min];
a[min] = a;
a = t;
}
System.out.println(""+Arrays.toString(arr));
}
return arr;
}

}

Can someone please tell me what the problem is?
 
Last edited by a moderator:
Technology news on Phys.org
What have you tried so far and what do you think is wrong?
 
Well, I've taken the structure of my bubble sort and put it into my selection sort. I'm just trying to change the code for the actual selection part. I'm just getting simple mistakes now..
 
It's doubt that it's that easy. I put the code in my IDE and it highlights several problems such that it won't compile. What's the error that you're getting when you try to compile?
 
tshet said:
Can someone please tell me what the problem is?
It's difficult for us to say what the problem is merely by looking at your code. Make it easier by giving us a clue about what you're seeing? Are you getting compile errors? (Another poster in this thread said that your code doesn't compile.) If it doesn't compile, what error message is the compiler giving you?

If the code compiles but throws and exception or otherwise doesn't behave like it should, give us that information, and in fact, any information that would help us help you.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...

Similar threads

Back
Top