佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1380|回复: 5

请问下?? 如何SORT multidimensional array

[复制链接]
发表于 2-5-2009 04:38 PM | 显示全部楼层 |阅读模式
google 了许多 网站 看到 都 要昏了

JAVA 例子 C++ 也好 只要知道 它的 FLOW

single 的就 可以了解 到了 multidimensional 就不行了

请高手指点指点下。
回复

使用道具 举报


ADVERTISEMENT

发表于 6-5-2009 07:49 PM | 显示全部楼层
请问multidimensional array的sort是什么意思?
你怎么分大小??
单纯的一个array,
int a[4] = {4,3,2,1};
sort后是{1,2,3,4}
1<2<3<4
但是multidimensional array呢?
回复

使用道具 举报

发表于 7-5-2009 09:57 PM | 显示全部楼层
可以給個example嗎?
不然不是很明白你要什麼
回复

使用道具 举报

发表于 15-5-2009 05:58 PM | 显示全部楼层
蛮有趣下。。。我从来都没有试过sort multidimensional array呢

{ 1 , 2 , 3 , 4 }
{ 1 , 2 , 3 , 4 }

嗯。。。这样算是sorted的multidimensional array吗?我觉得如果sorting MD array, the value of the current array index should be larger or equal to it's previous and top one.

Let say
array[2][4] = {
                     { 1 , 2 , 3 , 4 },
                     { 1 , 4 , 2 , 3 }
                    }

So, at array[2][2], it's at least equal or larger than array[2 - 1][2] and array[2][2 - 1], so is this consider as sorted? But, at array[2][3], it is smaller than array[2][2], so it should perform a swap. But what if after it swapped, it is smaller than array[1][2] (which means the top one). It's so complicated, sorry if something wrong with my algorithm.

But, if you are saying that, you only sort a multidemensional array based on 1 key, then it would be easier.

Such as, an array which contain Rank, Name. Then you only wanted to sort base on Rank. Then you can just sort it normally (with which ever sorting algorithm you want, such as insertion, selection or quicksort etc), and swap the data at the same time.

Or if you want things to be first sorted with Rank, and next sorted by the alphabetical order of Name. Then the only scenario where this would happen is, there exist more than 1 name with the same rank. But still, it would be easy, because you are still doing a linear swap, just that with a different condition.
回复

使用道具 举报

发表于 16-5-2009 01:22 AM | 显示全部楼层
何为sort multidimentional array ?

{4,1,3,2 }
{4,1,3,2 }

sort 后为

{1,2,3,4}
{1,2,3,4} ?

还是

{1,1,2,2,}
{3,3,4,4}

你要得哪一种?
回复

使用道具 举报

发表于 30-5-2009 12:07 AM | 显示全部楼层
如果要sort column or row就用sort single array的方法就行了
example:
{8,7,6,5}
{4,3,2,1}

for (i=0; i<array.length; i++)
for (j=0; j<array.length; j++)
......sort........(懒惰打,自己想)

如果要sort成酱的话
{1,2,3,4}
{5,6,7,8}

create new array
int[] a = new int[?]
copy to array a
sort
copy back

不过我不建议酱紫做,我觉得直接用single array更方便
回复

使用道具 举报

Follow Us
您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 11-12-2025 12:22 AM , Processed in 0.149553 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表