选择排序帮助..... [英] Selection sort help.....

查看:83
本文介绍了选择排序帮助.....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,

我创建了一个Comparable接口类Person。其中包含变量First_name,姓氏,月份(出生时间),日期(出生时间)和生日(我从月和日创建)。我有一个compareTo方法,它将比较生日时的两个人对象。如果生日是相同的,它输出int 0,如果一个更大则输出int 1,如果另一个更大,则输出int -1。我还创建了一个名为people的arraylist,它包含了人物。现在我正在尝试创建一个选择排序方法,它将对象排序为生日顺序,这是我到目前为止的代码,但我真的很难在现在做什么...



导入java.util.ArrayList。*;


公共类Main

{


public static void selectionSort(Comparable [] people)

{



for(int k = people。 length-1; k> 0; k - )

{

比较tmp;

int Large = 0;


for(int j = 1; j< = k; j ++)

{

if(people [j] .compareTo(people [k ])< 0)

{

大= j;

}

tmp =人[大] ;

人[大] =人[k];

人[k] = tmp;



}

}

}

}


任何帮助都会很棒,


非常感谢


Dave

解决方案

什么''这个问题?选择排序本身?在Google上有很多实现




亲切的问候,


Jos



有什么问题?选择排序本身?在Google上有很多实现




亲切的问候,


Jos



主要问题是获取人的生日并使用选择排序对它们进行排序。我有选择排序代码编译,但我不能让它看看数组人和生日排序对象。


我会在谷歌上看看,但是任何更多的帮助都会很棒。


谢谢


Dave



主要问题是获取人的生日并使用选择排序对他们进行排序。我有选择排序代码编译,但我不能让它看看数组人和生日排序对象。


我会在谷歌上看看,但是任何更多的帮助都会很棒。


谢谢


Dave

提示排序


HI,
I''ve created a Comparable interface class Person. Which has variables First_name, surname, month(Of birth), day(Of birth) , and birthday(which i have created from month and day). I have a compareTo method which will compare two person objects by the birthday. If the birthday are the same it outputs int 0, if one is bigger it outputs int 1 and if the other one is bigger it outputs int -1. I have also created an arraylist called people, which holds objects of person. Now i am trying to create a selection sort method which will sort the objects into birthday order, here is the code i have so far but am really stumped on what to do now...



import java.util.ArrayList.*;


public class Main
{

public static void selectionSort(Comparable[] people)
{


for (int k = people.length-1; k>0; k --)
{
Comparable tmp;
int Large = 0;

for (int j=1; j<= k; j++)
{
if (people[j].compareTo(people[k]) <0)
{
Large = j;
}
tmp = people[Large];
people[Large] = people[k];
people[k] = tmp;


}
}
}
}

Any help would be brilliant,

Thanks a lot

Dave

解决方案

What''s the problem? The selection sort itself? There are numerous implementations
available on Google.

kind regards,

Jos


What''s the problem? The selection sort itself? There are numerous implementations
available on Google.

kind regards,

Jos

The main problem is getting the birthdays of person and using selection sort to sort them. I have the selection sort code which compiles but i cant make it look into the array people and sort the objects by birthday.

I''ll have a look on google but any more help would be excellent.

Thanks

Dave


The main problem is getting the birthdays of person and using selection sort to sort them. I have the selection sort code which compiles but i cant make it look into the array people and sort the objects by birthday.

I''ll have a look on google but any more help would be excellent.

Thanks

Dave

Tips on sorting.


这篇关于选择排序帮助.....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆