快速确定阵列的方法是有问题的? [英] quick way to determine the array is irdered?

查看:84
本文介绍了快速确定阵列的方法是有问题的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,全部!


有一种简单的方法来确定该阵列,例如int X [N]包含有序的

项目(例如,升序),除了运行循环与

项目的比较?


给我提供一些有用的链接会很好:)


谢谢!


最诚挚的问候,罗马马沙克。电子邮件: mr*@tusur.ru

Hello, All!

Is there an easy way to determine that array e.g. int X[N] contains ordered
items (for example, ascending), except running loop with comparison of
items?

It would be good to provide me with some useful link :)

Thanks!

With best regards, Roman Mashak. E-mail: mr*@tusur.ru

推荐答案

在2005-06-17 21:53:36 -0400,Roman Mashak < mr*@tusur.ru>说:
On 2005-06-17 21:53:36 -0400, "Roman Mashak" <mr*@tusur.ru> said:
大家好!

有没有一种简单的方法来确定该阵列,例如int X [N]包含
有序项目(例如,升序),除了运行循环与
项目比较?
Hello, All!

Is there an easy way to determine that array e.g. int X[N] contains
ordered items (for example, ascending), except running loop with
comparison of items?




No.


-

Clark S. Cox,III
cl ******* @ gmail.com



No.

--
Clark S. Cox, III
cl*******@gmail.com


2005年6月18日星期六10:53:36 +0900 ,罗马马沙克 < mr*@tusur.ru>

在comp.lang.c中写道:
On Sat, 18 Jun 2005 10:53:36 +0900, "Roman Mashak" <mr*@tusur.ru>
wrote in comp.lang.c:
大家好!

是有一种简单的方法来确定该阵列,例如int X [N]包含有序的
项目(例如,升序),除了运行循环与
项目的比较?

为我提供一些有用的链接会很好:)

谢谢!

最诚挚的问候,罗马马沙克。电子邮件: mr*@tusur.ru




还有其他方法,但不太可能更快。


您可以使用相同类型和大小的第二个数组(已定义或

已分配)并将第一个数组复制到第二。然后你可以用$ q $ b用qsort()或你自己编写的排序函数排序第二个。


然后你可以逐个元素地比较两个数组,如果你找到了差别,第一个阵列没有订购。


但正如我所说,不太可能更快。

-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http:// www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://www.contrib.andrew.cmu.edu/~a...FAQ -acllc.html



There are other ways, but not likely to be quicker.

You could use a second array of the same type and size (defined or
allocated) and copy the first array into the second. Then you could
sort the second with qsort() or a sort function you write yourself.

Then you could compare the two arrays element by element and if you
find a difference, the first array was not ordered.

But as I said, not likely to be quicker.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

我想,一个简单的方法(而不是快速排序)在o(n)处做它的b $ b,(如果你的目标只是检查升序或降序
property)


检查整个

数组的连续元素之间的差异。


数组是升序还是降序,具体取决于差异..


(更多等等:

如果阵列在,则为
降序,一个元素总是比它的继承者更大

...只需检查整个数组..另一个

升序的方式..)

问候,

Devaraj Rangasamy

i guess, one simple way ( rather than going for quick sort ) of doing
it at o(n) is,(if ur goal is just to check ascending or descending
property)

Check the difference between the consecutive elements, for the whole
array.

The array is ascending or descending, depending on the difference..

(more blah-blah:

if an array is in descending order, an element will be always greater
than its successor... just check this for whole array.. and the other
way for asceding order..)
Regards,
Devaraj Rangasamy


这篇关于快速确定阵列的方法是有问题的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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