的std ::排序 [英] std::sort

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

问题描述

说我有

97456和

23456


是否已经有一个排序功能来检查哪一个以较小的

数字重新排列它。在这种情况下,底部数字应该明显是重新排列到顶部,因为它按数字顺序降低。

say i had
97456 and
23456

is there already a sort function to check which one begins with the smaller
number rearrange it. in this case the bottom number should clearly be
rearranged to the top as it lower in numerical order.

推荐答案

JasBascom写道:
JasBascom wrote:
说我有
97456和
23456

是否已经有一个排序功能来检查哪一个开始于
较小数字重新排列它。在这种情况下,底部数字应该明确地重新排列到顶部,因为它按数字顺序降低。
say i had
97456 and
23456

is there already a sort function to check which one begins with the
smaller number rearrange it. in this case the bottom number should
clearly be rearranged to the top as it lower in numerical order.




是的,它被称为std ::正如你已经猜到的那样排序:


std :: vector< int> v;

v.push_back(97456);

v.push_back(23456);

std :: sort(v.begin() ,v.end())


你不需要专门使用向量,它适用于所有容器,即
支持随机访问迭代器。 />

-

不可原谅



Yes, it''s called std::sort, as you already guessed:

std::vector<int> v;
v.push_back(97456);
v.push_back(23456);
std::sort(v.begin(), v.end())

You needn''t specifically use a vector, it works with all containers that
support random access iterators.

--
Unforgiven




"不可饶恕" < JA ******* @ hotmail.com>在消息中写道

news:c1 ************* @ ID-136341.news.uni-berlin.de ...

"Unforgiven" <ja*******@hotmail.com> wrote in message
news:c1*************@ID-136341.news.uni-berlin.de...
JasBascom写道:
JasBascom wrote:
说我有
97456和
23456

是否已经有一个排序功能来检查哪一个以
开头较小的数字重新排列它。在这种情况下,底部数字应该明确地重新排列到顶部,因为它按数字顺序降低。
say i had
97456 and
23456

is there already a sort function to check which one begins with the
smaller number rearrange it. in this case the bottom number should
clearly be rearranged to the top as it lower in numerical order.



是的,它被称为std :: sort,就像你一样已经猜到了:

std :: vector< int> v;
v.push_back(97456);
v.push_back(23456);
std :: sort(v.begin(),v.end())
<你不需要专门使用一个向量,它适用于所有支持随机访问迭代器的容器。



Yes, it''s called std::sort, as you already guessed:

std::vector<int> v;
v.push_back(97456);
v.push_back(23456);
std::sort(v.begin(), v.end())

You needn''t specifically use a vector, it works with all containers that
support random access iterators.




或者确保它们是排序开始使用:


std :: set< int> s;


s.insert(97456);

s.insert(23456);


int最小= * s.begin();


Jeff F



Or ensure they''re sorted to begin with using:

std::set<int> s;

s.insert(97456);
s.insert(23456);

int smallest = *s.begin();

Jeff F


抱歉打扰你了。

如果我有

联盟Allrecords {

struct crecord Newcrecord;

struct irrecord Newirrecord;

struct drecord Newdrecord;

}

union Allrecords * rec;

我想要排序的结构元素现在必须被访问抛出联合



rec.Newcrecord.customer_code;并且

rec.Newirrecord.customer_code和

rec.Newdrecord.customer_code。


这是从文件读入的,所以我不知道我会推回什么

(push_back)

如果我没有值放在括号中它是否仍然有效?

而不是std :: vector

我可以使用std :: rec吗?
sorry to bother you again.
if i had
union Allrecords{
struct crecord Newcrecord;
struct irrecord Newirrecord;
struct drecord Newdrecord;
}
union Allrecords *rec;
the structure element I want to sort now has to be accessed throw the union
say
rec.Newcrecord.customer_code; and
rec.Newirrecord.customer_code and
rec.Newdrecord.customer_code.

this is being read in from a file, so I don''t know what i would be pushing back
(push_back)
does it still work if I don''t have a value to put in the brackets?
instead of std::vector
could I use std::rec?


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

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