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

  • Context: Java 
  • Thread starter Thread starter tshet
  • Start date Start date
  • Tags Tags
    Java Sort
Click For Summary

Discussion Overview

The discussion revolves around issues encountered in a Java implementation of the selection sort algorithm. Participants are examining the code for errors and seeking clarification on specific problems related to its functionality and compilation.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant shares their selection sort code and asks for help identifying problems.
  • Another participant inquires about what the original poster has tried and what they believe is wrong with their code.
  • A participant notes that they have adapted their bubble sort structure for the selection sort but are encountering simple mistakes.
  • Another participant expresses doubt about the simplicity of the issue, mentioning that their IDE highlights several compilation problems.
  • A later reply requests more specific information about the errors encountered during compilation or runtime to better assist in troubleshooting.

Areas of Agreement / Disagreement

Participants do not appear to have reached a consensus on the specific issues with the code, as there are multiple perspectives on the nature of the problems and the need for more information.

Contextual Notes

Limitations include the lack of specific error messages or details about the compilation issues faced by the original poster, which hinders the ability to diagnose the problems effectively.

Who May Find This Useful

Readers interested in Java programming, algorithm implementation, and debugging practices may find this discussion relevant.

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.
 

Similar threads

  • · Replies 8 ·
Replies
8
Views
2K
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K