C / C ++中的数组最大值 [英] Maximum for Arrays in C/C++

查看:83
本文介绍了C / C ++中的数组最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须实现一些简单的排序算法。我不是要求你

做我的作业,但我的问题是如何存储整数。


我记得在这里读过一次运营商

[]必须接受的最大值。由于程序应该接受几乎任意数量的

整数,我不确定这个限制是否足够。


另外我想知道同样的关于STL-Vector类,因为我没有决定使用c或c ++。 Vector的速度怎么样?

它们是否可以作为链表实现,这会使存储新的
值慢得多?

谢谢< br $>
直到

-

请添加Salt and Peper到主题行绕过我的垃圾邮件过滤器

Hi,
I have to implement some simple sorting algorithm. I am NOT asking for you
to do my homework, but my question is rather on how to store the integers.

I recall reading once in here that there is a maximum value the operator
[] has to accept. Since the programm should accept almost any number of
integers, I am not sure if this limit will be enough.

Also I would like to know the same about the STL-Vector class, since I
haven''t decided wether to use c or c++. How about the speed of Vectors?
Could they be implemented as linked lists, which would make storing new
values much slower?
Thanks
Till
--
Please add "Salt and Peper" to the subject line to bypass my spam filter

推荐答案

" Till Crueger" <钛**** @ gmx.net>在消息中写道

news:c7 ********** @ f1node01.rhrz.uni-bonn.de ...
"Till Crueger" <Ti****@gmx.net> wrote in message
news:c7**********@f1node01.rhrz.uni-bonn.de...
我必须实现一些简单的排序算法。我不是要求你做我的作业,但我的问题是如何存储整数。

我记得在这里读过一次,操作员有一个最大值
[]必须接受。由于程序应该接受几乎任意数量的整数,我不确定这个限制是否足够。


理论上的限制是标准类型''size_t''可表示的最大值

(实现定义的

无符号整数类型,由< stdlib.h>以及其他

头文件声明),但实际最大值也将限于

可用内存(对于动态分配的数组) ,或者是文件范围或本地数组的编译器限制的
。对于

许多编译器这些限制是可配置的。检查你的

文件。

我也想知道关于STL-Vector类的相同信息,


< ; OT for clc>

std :: vector<> :: max_size()返回的值将告诉

你可以存储的最大元素数量(这个

的实际值将取决于你的实现。)这再次

也将受到可用内存的限制。

< / OT for clc> ;

因为我没有决定使用c或c ++。矢量速度怎么样?


要知道的唯一方法是同时尝试数组和向量,并且

来衡量差异。这也取决于你的实现。

C和C ++语言都没有提出速度的要求,

唯一的行为。但是要研究C ++

标准容器的复杂性要求。

它们是否可以作为链表实现,这将使存储新的
值更慢?
Hi,
I have to implement some simple sorting algorithm. I am NOT asking for you
to do my homework, but my question is rather on how to store the integers.

I recall reading once in here that there is a maximum value the operator
[] has to accept. Since the programm should accept almost any number of
integers, I am not sure if this limit will be enough.
The theoretical limit is the maximum value representable
by the standard type ''size_t'' (an implementation-defined
unsigned integer type, declared by <stdlib.h> among other
headers), but the actual maximum will be also limited to
available memory (for dynamically allocated arrays), or
by compiler limits for file scope or local arrays. For
many compilers these limits a configurable. Check your
documentation for that.

Also I would like to know the same about the STL-Vector class,
<OT for clc>
The value returned by std::vector<>::max_size() will tell
you the maximum number of elements the vector can store (this
actual value will depend upon your implementation.) This again
will also be limited by available memory.
</OT for clc>
since I
haven''t decided wether to use c or c++. How about the speed of Vectors?
The only way to know is to try both an array and a vector, and
measure the difference. This will also depend upon your implementation.
Neither the C nor C++ language makes an requirements about ''speed'',
only behavior. But do research the ''complexity requirements'' of the C++
standard containers.
Could they be implemented as linked lists, which would make storing new
values much slower?




< cl for clc>

可以使用链表(例如std :: list<>),是。但是存储值的存储值的性能具有依赖性。对于矢量,在末尾添加元素

通常比在其他地方插入元素更快。在任意位置插入

的列表通常比使用

向量更快。 < / OT for clc>


-Mike



<OT for clc>
A linked list (e.g. std::list<>) could be used, yes. But the performance of
storing values has dependencies. For a vector, adding elements at the end
will typically be faster than inserting elements elsewhere. Inserting
at an arbitrary location will typically be faster with a list than with a
vector. </OT for clc>

-Mike




" Till Crueger" <钛**** @ gmx.net>在消息中写道

news:c7 ********** @ f1node01.rhrz.uni-bonn.de ...

"Till Crueger" <Ti****@gmx.net> wrote in message
news:c7**********@f1node01.rhrz.uni-bonn.de...
我必须实现一些简单的排序算法。我不是要求你做我的作业,但我的问题是如何存储整数。

我记得在这里读过一次,操作员有一个最大值
[]必须接受。由于程序应该接受几乎任意数量的整数,我不确定这个限制是否足够。


我不知道标准说的是什么但是如果阵列的

大小受到金额以外的任何限制,我会非常惊讶可用

内存。

我也想知道关于STL-Vector类的相同内容,因为我没有决定使用c或者c ++。矢量速度怎么样?


它们很快,可能不如普通阵列那么快,但它们是一个更方便的
该死的网站。尝试两种方式并计时,它是找到

的唯一方法。

它们可以实现为链表,这会使存储新的值更慢?
Hi,
I have to implement some simple sorting algorithm. I am NOT asking for you
to do my homework, but my question is rather on how to store the integers.

I recall reading once in here that there is a maximum value the operator
[] has to accept. Since the programm should accept almost any number of
integers, I am not sure if this limit will be enough.
I don''t know what the standard says but I would be very surprised if the
size of an array was limited by anything other than the amount of available
memory.

Also I would like to know the same about the STL-Vector class, since I
haven''t decided wether to use c or c++. How about the speed of Vectors?
They''re fast, might not be as quite fast as ordinary arrays, but they are a
damn site more convenient. Try both and time them, its the only way to find
out.
Could they be implemented as linked lists, which would make storing new
values much slower?




不能将它们作为链表实现。它们是使用

阵列实现的。


P.S.最后你的'奇迹般的错误

计算'的问题是什么,我很想知道。


john



No they cannot be implemented as linked lists. They are implemented using
arrays.

P.S. In the end what was the problem with your ''miraculously incorrect
calculations'', I''m curious to know.

john


2004年5月5日星期三20:21:27 +0100,John Harrison写道:
On Wed, 05 May 2004 20:21:27 +0100, John Harrison wrote:
PS最后你的奇迹般不正确的计算出现了什么问题,我很想知道。
P.S. In the end what was the problem with your ''miraculously incorrect
calculations'', I''m curious to know.




好​​吧,它不是'实际上在我发布的代码中,但是花了我很长时间

来计算出来。它有助于将代码分解为包含该错误的小块。在某处,我调用了

Vector的方法标准化。我理所当然地认为这个方法是以const的形式实现的,但是它不是
。因此错误的结果。因为我从来没有猜到这个

方法可能会对我的对象造成严重破坏,所以我没有包含它。猜猜我做了很多

我下次发布代码时更好* gg *。

直到


-

请添加Salt and Peper到主题行绕过我的垃圾邮件过滤器



Well, it wasn''t actually in the code I posted, but it took me a long time
to figure that out. It helped to break the code down to small pieces still
containing the bug. Somewhere along I called the method normalize of the
Vector. I took it for granted this method was implemented as const, but it
wasn''t. Hence the wrong results. Since I would have never guessed this
method might wreak havoc on my object I didn''t include it. Guess I do much
better when I post code the next time *gg*.
Till

--
Please add "Salt and Peper" to the subject line to bypass my spam filter


这篇关于C / C ++中的数组最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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