按一定数量排序列表? [英] Sorting a list by a certain number?

查看:144
本文介绍了按一定数量排序列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要对包含每个人年龄的数组列表进行排序,但是我必须打印出超过65岁的人员列表。我知道如何在SQL中执行此操作,而不是Java。任何帮助,将不胜感激。谢谢!

I need to sort an array list which includes an age for each person, but I have to print out a list of people over 65. I know how to do this in SQL but not Java. Any help would be appreciated. Thanks!

推荐答案

首先确保你已经完全说明了问题,然后考虑你将首先使用的算法(不是特定语言);然后实现算法。

First make sure you have the problem stated fully, then think about the algorithm you will use first (that is not language specific); then implement the algorithm.

如果问题只是列出年龄超过65岁(不是65岁或以上?)的阵列中的所有人,那么你只需要循环遍历数组,并为每一行检查年龄是否符合标准。如果是,请打印此人。

If the problem is simply to list all people in an array whose age is over 65 (not 65 or older?), then you only need to loop through the array and, for each line, check to see if the age meets the criteria. If it does, print out the person.

如果您需要对列表进行排序,请先执行此操作。 (如果列表很长,则使用冒泡排序或更有效的排序);然后逐步浏览列表,直到找到截止年龄并打印出所有剩余时间。

If you need to sort the list, then do that first. (Use bubble sort or a more efficient sort if the list is long); then step through the list until you find the cutoff age and print out all the rest.

这篇关于按一定数量排序列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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