English 中文(简体)
a. 按摩六类分列的职业选择日期
原标题:Sorting date with radix sort
  • 时间:2012-05-02 05:36:36
  •  标签:
  • c

我有一系列具体的日期,格式为<编码>d/mm/yyyyyy。

我想按月和逐年按摩擦地确定日期,但我不知道,因为最终会根据月数最多的计算。

for example i have the following array: 16/04/2012 01/05/2013 01/02/2012 10/11/2012 01/12/2012

normally the result after the sort is: 01/02/2012 16/04/2012 01/05/2013 10/11/2012 01/12/2012

while what i want is: 01/02/2012 16/04/2012 10/11/2012 01/12/2012 01/05/2013 year 2012 first then 2013

i n t使该代码作了改动,因为我不知道算法是如何运作的,而且我不得不使用,只有1 radix

最佳回答

不要把日期划分在你们的代表权上,而是以单独的方式来考虑。 例如,在01/02/2012年这一天,形成了一种关键的20120201。 现在,两位数的顺序从最多到最不重要,你可以将关键数作为数字处理,并将之分应用于这些数字。

If you wish, you don t have to explicitly create the sort keys, but then you d have to modify the code that picks a digit for a round of radix sort to enforce proper order.

问题回答

你们需要两次使用混合体,首先是在本月,然后是当年。 如果你只使用rad,那么你就不得不在这一年进行分类,那么,同年之内的几个月不会被命令。 也许你可以在一年内对数月采用不同的算法,或者根本不使用混合法。 是否有特别原因,为什么你只能一度?





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签