对2D阵列进行排序 [英] Sorting 2D-array

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

问题描述

您好,


我正在尝试将我的2D数组排序,但出于某种原因,我似乎无法按正确的顺序对其进行排序。有谁可以帮我找到解决方案?


我有一个数组,其构造如下

Hello,

I''m trying to get my 2D-array sorted but for some reason I can''t seem to get it sorted in the right order. Anybody that can help me find the solution?

I have an array which has been constructed as follows

展开 | 选择 | Wrap | 行号

推荐答案

你得到的是什么而不是你想要的?
What are you getting instead of what you want?


现在我得到的是这样的东西:


person(0)(" NAME1",4,51,55,1,5)

person(1)(" NAME2",12,41, 53,2,3)

person(2)(NAME3,24,35,59,3,1)

person(3)(" NAME4" ;,1,11,12,4 ,2)

person(4)(" NAME5",0,22,22,5,4)


它没有被排序好吧。
Right now I''m getting something like this:

person(0) ("NAME1", 4, 51, 55,1,5)
person(1) ("NAME2", 12, 41, 53,2,3)
person(2) ("NAME3", 24, 35, 59,3,1)
person(3) ("NAME4", 1, 11, 12,4,2)
person(4) ("NAME5", 0, 22, 22,5,4)

It''s not being sorted well.


1)在进行任何排序之前,您应该为所有元素设置先前的位置。否则,它就不会出现问题。


2)如果一个值大于另一个值,则交换位置。但是如果位置也更大,你只能交换。你不可能每次交换它们,否则你可能会将它们交换到错误的位置。
1) You should set the previous positions for all elements before doing any sorting. Otherwise, it won''t come out correct.

2) You are swapping the positions if one value is larger than the other. But you only swap if the position is also larger. You can''t swap them everytime otherwise you might swap them into the wrong position.


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

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