由买买提看人间百态

topics

全部话题 - 话题: vector
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
g****g
发帖数: 1828
1
来自主题: WaterWorld版 - vector
SGI Logo
vector

Category: containers Component type: type
Description
A vector is a Sequence that supports random access to elements, constant
time insertion and removal of elements at the end, and linear time insertion
and removal of elements at the beginning or in the middle. The number of
elements in a vector may vary dynamically; memory management is automatic.
Vector is the simplest of the STL container classes, and in many cases the
most efficient.
Example
vector V;
... 阅读全帖
l******9
发帖数: 579
2
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: data clustering by vector correlation distance
发信站: BBS 未名空间站 (Wed Feb 26 11:17:21 2014, 美东)
I am working on data analysis.
Given a group of data vectors, each of them has the same dimension. Each
element in a vector is a floating point number.
V1 [ , , , … ]
V2[ , , , … ]
...
Vn [ , , , … ]
Suppose that each vector has M numbers. M can be 10000.
n can be 200.
I need to find out how to partition the n vector... 阅读全帖
l******9
发帖数: 579
3
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: data clustering by vector correlation distance
发信站: BBS 未名空间站 (Wed Feb 26 11:17:21 2014, 美东)
I am working on data analysis.
Given a group of data vectors, each of them has the same dimension. Each
element in a vector is a floating point number.
V1 [ , , , … ]
V2[ , , , … ]
...
Vn [ , , , … ]
Suppose that each vector has M numbers. M can be 10000.
n can be 200.
I need to find out how to partition the n vector... 阅读全帖
l******9
发帖数: 579
4
I am working on data analysis.
Given a group of data vectors, each of them has the same dimension. Each
element in a vector is a floating point number.
V1 [ , , , … ]
V2[ , , , … ]
...
Vn [ , , , … ]
Suppose that each vector has M numbers. M can be 10000.
n can be 200.
I need to find out how to partition the n vectors into sub-groups such that
each vector in one subgroup can be represented by a basic vector in the
subgroup.
For example,
W = union of V1, V2, V3 … Vn
Find subgroup i... 阅读全帖
m******t
发帖数: 273
5
【 以下文字转载自 Statistics 讨论区 】
发信人: myregmit (myregmit), 信区: Statistics
标 题: Predict values of vectors by other vectors generated by black box
functions
发信站: BBS 未名空间站 (Sun Mar 2 11:38:56 2014, 美东)
Hi,
I need to solve a problem about predicting values of some numerical vectors
by using other numerical vectors with all these vectors in the same vector
set, which is generated by one or more black box functions.
Given a vector space:
P =[S_1, S_2, …, S_T | Sk is a vector of q numbers, k = 1, ..., T]... 阅读全帖
m******t
发帖数: 273
6
【 以下文字转载自 Statistics 讨论区 】
发信人: myregmit (myregmit), 信区: Statistics
标 题: Predict values of vectors by other vectors generated by black box
functions
发信站: BBS 未名空间站 (Sun Mar 2 11:38:56 2014, 美东)
Hi,
I need to solve a problem about predicting values of some numerical vectors
by using other numerical vectors with all these vectors in the same vector
set, which is generated by one or more black box functions.
Given a vector space:
P =[S_1, S_2, …, S_T | Sk is a vector of q numbers, k = 1, ..., T]... 阅读全帖
m******t
发帖数: 273
7
【 以下文字转载自 Statistics 讨论区 】
发信人: myregmit (myregmit), 信区: Statistics
标 题: Predict values of vectors by other vectors generated by black box
functions
发信站: BBS 未名空间站 (Sun Mar 2 11:38:56 2014, 美东)
Hi,
I need to solve a problem about predicting values of some numerical vectors
by using other numerical vectors with all these vectors in the same vector
set, which is generated by one or more black box functions.
Given a vector space:
P =[S_1, S_2, …, S_T | Sk is a vector of q numbers, k = 1, ..., T]... 阅读全帖
m******t
发帖数: 273
8
【 以下文字转载自 Statistics 讨论区 】
发信人: myregmit (myregmit), 信区: Statistics
标 题: Predict values of vectors by other vectors generated by black box
functions
发信站: BBS 未名空间站 (Sun Mar 2 11:38:56 2014, 美东)
Hi,
I need to solve a problem about predicting values of some numerical vectors
by using other numerical vectors with all these vectors in the same vector
set, which is generated by one or more black box functions.
Given a vector space:
P =[S_1, S_2, …, S_T | Sk is a vector of q numbers, k = 1, ..., T]... 阅读全帖
g*****1
发帖数: 998
9
【 以下文字转载自 JobHunting 讨论区 】
发信人: guagua1 (), 信区: JobHunting
标 题: 请教c++的string vector问题,谢谢!
发信站: BBS 未名空间站 (Mon Feb 28 11:16:46 2011, 美东)
下面这段代码,在vc express2010里编译通不过,但是我试了g++就可以。
另外,我把string vector改成注解掉的那段里的int vector, vc就可以通过。
请问我这个应该怎么改一下呢?我希望在vc里用。
#include
#include
#include
#include
using namespace std;
int main () {

char *m1[] = {"a","e","c","m"};
vector v1(m1,m1+4);
char *m2[] ={"n"};
vector v2(m2,m2+1... 阅读全帖
b***i
发帖数: 3043
10
我们有个类,叫Pole吧
std::vector PoleAccess::Load(...){
std::vector poles;
... 动态生成Pole对象,加入到vector里面
return poles;
}
然后,有另一个类,HPleManager,里面要这样做
std::vector* PoleManager::LoadHole(
return new std::vector(PoleAccess::Load(...));
}
1 这样的话,是不是一开始有一个vector在栈上,然后为了返回堆上的指针,把内容复
制到了堆上?
2 这个new std::vector(Pole)是move constructor还是copy?
3 但是为了把栈上的变量移动到堆上,还是得copy吧?当然,只是一个vector容器的信
息而已,真正vector内容都在堆上吧。而且,内容指向的Pole对象也都在堆上。
4 这个过程RVO负责直接优化到堆上吗?我问这个问题是因为我需要把PoleAcces... 阅读全帖
m******t
发帖数: 273
11
Hi,
I need to solve a problem about predicting values of some numerical vectors
by using other numerical vectors with all these vectors in the same vector
set, which is generated by one or more black box functions.
Given a vector space:
P =[S_1, S_2, …, S_T | Sk is a vector of q numbers, k = 1, ..., T]
Find a sub-group of vectors g = {S_d | d belongs to 1, …, T } and a
function h( S_d )
Such that
Difference between the value of h(S_g) and S_r is minimized
set g + set r = set P
... 阅读全帖
g*****1
发帖数: 998
12
来自主题: JobHunting版 - 请教c++的string vector问题,谢谢!
下面这段代码,在vc express2010里编译通不过,但是我试了g++就可以。
另外,我把string vector改成注解掉的那段里的int vector, vc就可以通过。
请问我这个应该怎么改一下呢?我希望在vc里用。
#include
#include
#include
#include
using namespace std;
int main () {

char *m1[] = {"a","e","c","m"};
vector v1(m1,m1+4);
char *m2[] ={"n"};
vector v2(m2,m2+1);

vector u;
/* int m1[] = {1,2,3,4};
vector v1(m1,m1+4);
int m2[] ={100};
vector v2(m2,m2+1);

vector... 阅读全帖
b***y
发帖数: 2799
13
☆─────────────────────────────────────☆
slipper (ohh) 于 (Sat Oct 8 22:49:06 2005) 提到:
if not use array declaretion in c to construct a 3-dim array, is it possible
to use vector to construct a 3-dim array ?if so, how, can somebody point me to
some sample code? Thanks.
☆─────────────────────────────────────☆
aZhu (a+zhu) 于 (Sat Oct 8 22:55:44 2005) 提到:
vector a(n); //1-d
vector > a(n, vector (m)); //2-d, n * m
vector > > a (k, vector
S**I
发帖数: 15689
14
来自主题: JobHunting版 - 请教c++的string vector问题,谢谢!
error message说的很清楚:string类的operator<没有定义,改成这样子就行了:
#include
#include
#include
#include
#include
using namespace std;
bool comp(const string& s1, const string& s2){
return strcmp(s1.c_str(), s2.c_str()) < 0;
}
int main () {
char *m1[] = {"a","e","c","m"};
vector v1(m1,m1+4);
char *m2[] ={"n"};
vector v2(m2,m2+1);
vector u;
/* int m1[] = {1,2,3,4};
vector v1(m1,m1+4);
int m2[] ={... 阅读全帖
f**********t
发帖数: 1001
15
来自主题: JobHunting版 - 实现vector的iterator,template问题
实现了vector的iterator,包括Next(), hasNext(), peek()等功能。
但是一旦用template写又卡住了。
这里vector::iterator it; 会出错:missing ";" before identifier "it"
感觉是个编译问题,但不知怎么fix. 求指教。多谢!=)
template class VectorIterator {
vector vec_;
vector::iterator it;
public:
VectorIterator(vector &vec) {
vec_ = vec;
it = vec_.begin();
}
bool hasNext() {
return it != vec_.end();
}
T next() {
if (!hasNext()) {
throw exception("End of vector");
... 阅读全帖
c*********n
发帖数: 128
16
来自主题: Programming版 - 请问vector
It means you can define vector, in which obj could be various types.
E.g. vector is a vector of int, while vector is a vector of
chicks.
However, for a particular vector you defined, all the elements have to
be of type obj, i.e. vector only holds chicks.
K***a
发帖数: 497
17
function(vector a)
{
    vector::iterator ater = a.begin();
    vector::iterator bter = a.begin();
    
    cout <<*ater <     cout <<*(ater+1) <     for(bter; bter != a.end; bter++)
    {
        cout <<*bter;
    }
}
调用function两次。在两次调用中,ater都能输出vector a中每个数据。但是bter只有
在第一次调用中能输出vector a... 阅读全帖
h**l
发帖数: 168
18
1 这样的话,是不是一开始有一个vector在栈上,然后为了返回堆上的指针,把内容复
制到了堆上?
yeah, just copy the container info from stack to heap.
2 这个new std::vector(Pole)是move constructor还是copy?
should be move as the method returns r-value.
3 但是为了把栈上的变量移动到堆上,还是得copy吧?当然,只是一个vector容器的信
息而已,真正vector内容都在堆上吧。而且,内容指向的Pole对象也都在堆上。
move constructor of the vector container is used, the container information
is copied from stack to heap, the vector elements (Pole*) are moved
4 这个过程RVO负责直接优化到堆上吗?我问这个问题是因为我需要把PoleAccess::
Load返回的每一个Pole对象... 阅读全帖
m*******o
发帖数: 264
19
来自主题: Java版 - VECTOR一问
import java.util.*;
public class test {
public static void main(String args[]){
double S=100.0;

Vector> Stree = new Vector>();
Vector Svec = new Vector();

Svec.add(S);
Stree.add(Svec);
Svec.add(S+1);
Stree.add(Svec);


System.out.println("After loop Stree 0 is "+Stree.get(0));
System.out.println("After loop Stree 1 is "+Stree.get(1));
}
}
f**********w
发帖数: 93
20
来自主题: Programming版 - 问个C++ 中拷贝vector的问题
我想实现以下操作,不知道这么做对不对?
//...
vector< vector< vector > > v3d;
//initialize v3d here....
vector< vector< vector > >v3d_dup(v3d.begin(), v3d.end() );
在这里的拷贝是把三维的数据都拷贝过来,
比如说v3d_dup[xi][yi][zi] == v3d[xi][yi][zi]应为真。是吧,
谢谢。
N****p
发帖数: 1691
21
一个C++的设计问题:
一个Class含有一个vector h,Constructor参数可能是空,然后Elem一个一个push进来
,也有可能是一个vector(可能很长,10^9)。
后一种情况要求In-place,前一种情况就要创建一个vector。
目前是把h定义为一个Reference,如下实现的,求建议和拍砖
MyHeap() : h(*(new std::vector())), hispassedin(false) {}
MyHeap(std::vector & _h): h(_h), hispassedin(true)
{
heapify_full(h);
}
~MyHeap(){if(!hispassedin) delete &h;}
private:
std::vector & h; // Note: This is a reference!
bool hispassedin;
z*******h
发帖数: 346
22
https://www.cprogramming.com/c++11/rvalue-references-and-move-semantics-in-c
++11.html
vector变量是allocate在stack上,但是里面的东西是allocate在heap上,这样move
semantics就allocate一个新的vector object(里面就装size和一个pointer,不费内存
),但是C++11就不在heap上重新为vector里面的东西allocate memory了,它就偷偷地
把rvalue vector里面的pointer偷过来。
你的vector里面装的是指针,那么这些指针们allocate在heap上,每个再指向那些heap
上的pole们。我觉得你直接在vector里装pole不更省事吗?
l*****1
发帖数: 137
23
我有一个问题请教:
请先看附件中的简图,GaAs单量子阱样品, 样品温度保持在40K, 用能量对应于量子阱
的重空穴吸收峰的光子激发GaAs单量子阱,可以在量子阱中激发出激子(exciton),
我的问题是,光子的wave vector (k) 是否全部传递给了激子?如果是的话,激子的
in plane wave vector 应该是k// = k sinθ,这种理解是否正确?
我现在有一个实验,需要在GaAs单量子阱中生成具有一定in plane wave vector的激子
,我希望这个in plane wave vector是可以控制的,上面提到的是我现在的想法。即使
我的想法是对的,也不完美,因为这种方法生成的激子in plane wave vector有一个极
限,不会很大。哪位有更好的方法,可以在GaAs点量子阱中生成可控in plane wave
vector的激子。
t*******i
发帖数: 4960
24
bool dp[size][size]; // Accepted

vector> dp(size, vector(size, false)); // 超时
就上面一行不同,为啥vector 就超时呢?
在visual studio里不能这么定义数组,必须分配空间,所以想用 vector
i**p
发帖数: 902
25
Which one is the a valid function prototype? Is it C only?
A. template void Display(std::vector& obj);
B. template void Display(std::vector& obj);
C. template void Display(std::vector& obj);
D. template void Display(std::vector& obj);
E. template void Display(std::vector& obj);
w****r
发帖数: 1384
26
来自主题: Programming版 - vector< vector > > 怎么初始化?
有一个问题,就是用到如下数据结构,
vector< vector > > VofV;
其中VofV的某些位置是空的,没有数据的,
有些是带一个列表的,该怎么初始化?
我直接设置比如VofV.at(i).at(j).push_back(data d1) 被说out_of_range。后来领悟
过来没有初始化,所以(i,j)是没有数据的。
另外,VofV的大小是不固定的,随运行时需要变化。
list > >考虑过,凡是实际需要还是vector of vector更符合应
用。
大侠给点意见把。谢谢。
h********n
发帖数: 1671
27
来自主题: Programming版 - static vector 怎么 initialize ?
向别人问问题起码要虚心一点,自己问的不清楚也不能责怪别人,别人来回答已经是很
热心了。
static变量可以用一个函数的返回值来初始化,可以任意复杂,也不限于class member
。但是复杂数据结构的static变量最好不要进行复杂的初始化。如果只是book
knowledge,最好是直接用char* array,不要用vector。如果必需要用有复杂
数据结构的static变量,最好是先缺省初始化为empty,然后在main()里动态的进行初
始化。
using namespace std;
struct A
{
static vector v;
static vector f(){ vector v; v.push_back("123"); v.push_back
("abc"); return v;}
};
vector A::v = A::f();
int main()
{
cout << A::v[0] << " " << A::v[1] << endl;
}
h********n
发帖数: 1671
28
来自主题: Programming版 - static vector 怎么 initialize ?
向别人问问题起码要虚心一点,自己问的不清楚也不能责怪别人,别人来回答已经是很
热心了。
static变量可以用一个函数的返回值来初始化,可以任意复杂,也不限于class member
。但是复杂数据结构的static变量最好不要进行复杂的初始化。如果只是book
knowledge,最好是直接用char* array,不要用vector。如果必需要用有复杂
数据结构的static变量,最好是先缺省初始化为empty,然后在main()里动态的进行初
始化。
using namespace std;
struct A
{
static vector v;
static vector f(){ vector v; v.push_back("123"); v.push_back
("abc"); return v;}
};
vector A::v = A::f();
int main()
{
cout << A::v[0] << " " << A::v[1] << endl;
}
r****t
发帖数: 10904
29
来自主题: Programming版 - static vector 怎么 initialize ?
这个地方 vector A::v = A::f();
这一句没有像你说的一样写在 main() 里面,是笔误,还是就应该在外面?

member
struct A
{
static vector v;
static vector f(){ vector v; v.push_back("123"); v.push_back
("abc"); return v;}
};
vector A::v = A::f();
int main()
{
cout << A::v[0] << " " << A::v[1] << endl;
}.
y**b
发帖数: 10166
30
来自主题: Programming版 - 多维数组用vector是不是更方便?
这几天用了几次动态多维数组,感觉用vector比new要方便一些,
也不容易出错,比如一个四维数组:
// 4-dimensional array of cellVec
typedef pair > cellT;
vector< vector< vector < cellT > > > cellVec;
cellVec.resize(nx);
for (int i = 0; i < cellVec.size(); ++i) {
cellVec[i].resize(ny);
for (int j = 0; j < cellVec[i].size(); ++j)
cellVec[i][j].resize(nz);
}
// mark each cell as not searched
for (int i = 0; i < nx; ++i)
for (int j = 0; j < ny; ++j)
for (int k = 0; k < nz; ++k) {
... 阅读全帖
n********r
发帖数: 719
31
code是这样的
void func() {
vector > result;
for(int i=0; i
......
std::vector vec(M);
for (int j=0; j vec[j] = tmp[j];
result.push_back(vec);
......
}
}
设置断点debug发现, 在第一次result.push_back(vec)之后
result的size由0变为1
但是result[0]是一个empty的vector
第二次push_back的时候程序就crash了
哪里出问题了呢?
z*******h
发帖数: 346
32
我不是C++大牛,不过最近正好也碰到了同样的问题。
我觉得 new std::vector(PoleAccess::Load(...)) 是copy constructor复制
了一个object, 不是move.
你问什么不这样定义呢?
std::vector PoleManager::LoadHole(
std::vector poles = PoleAccess::Load(...);
return poles;
}
这样应该是用C++11的move semantics
你可以参照一下
https://stackoverflow.com/questions/15704565/efficient-way-to-return-a-
stdvector-in-c
我们公司的C++大牛们写的code都是return vector的,而不是pointer to vector.
y**b
发帖数: 10166
33
说的对,pointer to vector,那还要vector干嘛;
容器就是设计用来避免数组和指针这类不强健的用法,
还去new个容器。


: 我不是C 大牛,不过最近正好也碰到了同样的问题。

: 我觉得 new std::vector(PoleAccess::Load(...)) 是copy constructor
复制

: 了一个object, 不是move.

: 你问什么不这样定义呢?

: std::vector PoleManager::LoadHole(

: std::vector poles = PoleAccess::Load(...);

: return poles;

: }

: 这样应该是用C 11的move semantics

: 你可以参照一下

e********2
发帖数: 495
34
报错
required from 'std::pair<_T1, _T2>::pair(std::piecewise_construct_t, std::
tuple<_Args1 ...>, std::tuple<_Args2 ...>) [with _Args1 = {const int&}; _
Args2 = {}; _T1 = const int; _T2 = std::pair&>]'
class Employee {
public:
int id;
int importance;
std::vector subordinates;
};
class Solution_690 {
public:
int aux(std::unordered_map&>>&
parents, int ind) {
int res = parents[ind].first;
for (auto& t : par... 阅读全帖
z*******o
发帖数: 1794
35
貌似不矛盾吧。我没有说小片段就是insert,大片段就是vector阿。是否生长取决于带
有抗性基因的vector片段能否环化,而能否环化的关键是vector和insert能否连上。我
的理解是,在连接的这个阶段,只是碱基的连接,和vector上面的东西关系不大,那些
东西是用来扩增的。如果只考虑连接的话,你觉得vector和insert有什么区别么?无非
就是两个线性DNA进行环化而已。粘末端的连接效率显然比平端的效率高,所以建议楼
主试double digest。
l******9
发帖数: 579
36
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: two vectors' coefficient of determination
发信站: BBS 未名空间站 (Wed Mar 5 23:09:58 2014, 美东)
I have a question about coefficient of determination.
I need to find the relationship of two vectors.
Given two numerical vectors x and y, their determination of coefficient can
be expressed as :
1 - ( 1 - (dot_product(x,y))^2 / (|x|^2 + |y|^2)) / (1 - |y| * |y|/ ( y
'dimension * |y|^2 ) )
|x|^2 = sum of squared of each eleme... 阅读全帖
l******9
发帖数: 579
37
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: two vectors' coefficient of determination
发信站: BBS 未名空间站 (Wed Mar 5 23:09:58 2014, 美东)
I have a question about coefficient of determination.
I need to find the relationship of two vectors.
Given two numerical vectors x and y, their determination of coefficient can
be expressed as :
1 - ( 1 - (dot_product(x,y))^2 / (|x|^2 + |y|^2)) / (1 - |y| * |y|/ ( y
'dimension * |y|^2 ) )
|x|^2 = sum of squared of each eleme... 阅读全帖
l******9
发帖数: 579
38
【 以下文字转载自 Statistics 讨论区 】
发信人: light009 (light009), 信区: Statistics
标 题: two vectors' coefficient of determination
发信站: BBS 未名空间站 (Wed Mar 5 23:09:58 2014, 美东)
I have a question about coefficient of determination.
I need to find the relationship of two vectors.
Given two numerical vectors x and y, their determination of coefficient can
be expressed as :
1 - ( 1 - (dot_product(x,y))^2 / (|x|^2 + |y|^2)) / (1 - |y| * |y|/ ( y
'dimension * |y|^2 ) )
|x|^2 = sum of squared of each eleme... 阅读全帖
i*********5
发帖数: 19210
39
【 以下文字转载自 Cycling 讨论区 】
发信人: wuyan (wuyan), 信区: Cycling
标 题: First hands-on look & rides with the Garmin Vector power meter
发信站: BBS 未名空间站 (Wed Aug 7 11:13:51 2013, 美东)
$1699 Garmin Vector power meter
dcrainmaker的评测出来了。
http://www.dcrainmaker.com/2013/08/hands-on-garmin-vector.html
发信人: wuyan (wuyan), 信区: Cycling
标 题: Re: First hands-on look & rides with the Garmin Vector power m
发信站: BBS 未名空间站 (Wed Aug 7 12:44:04 2013, 美东)
几点读后感。
1、Metrigear在被garmin收购之前,准备选用Speedplay pedal脚踏系统,不过最后改
用了LOOK ... 阅读全帖
s*****o
发帖数: 1540
40
来自主题: JobHunting版 - max sub vector sum 问题
一个经典问题:a vector x of n real numbers. find the max sum found in any
contiguous sub vector。
大家知道,programming pearl的解法是:
maxsofar = 0;
maxendinghere = 0;
for i = [0, n)
maxendinghere = max (maxendinghere + x[i], 0);
maxsofar = max (maxsofar, maxendinghere);
我改动一下,要输出究竟是那个sub vector,请大侠指教是不是正确。
public class MaxSubVector {
static public void findBigestSum(double[] x)
{
double maxsofar = 0;
double maxendinghere = 0;
int maxsofarlow = -1;
int maxso... 阅读全帖
g**u
发帖数: 583
41
请问大家, 如何有效的实现permute vector of vectors.
例如:
输入为{ {2,1}, {4,3}}
期待的输出为:
{2,1,4,3}
{2,1,3,4}
{1,2,3,4}
{1,2,4,3}
希望使用 next_permutation来实现,也尝试将数值map到index,然后permute index,
在输出的时候再返回;但是当有3个或者以上的vectors的时候发现卡住了
请各位大牛指点,谢谢
m*p
发帖数: 1331
42
【 以下文字转载自 JobHunting 讨论区 】
发信人: mbp (Mac Book Pro), 信区: JobHunting
标 题: java: use vector to shuffle a deck of Card 问题
发信站: BBS 未名空间站 (Thu Mar 3 00:40:48 2011, 美东)
要求用vector实现shuffle a deck of Card,如下:
public class Card {
private int value;
Card(int v) {
value = v;
}

public void print(){
System.out.print(value+";");
}
}
public class DeckShuffle {

private final int num;
Vector deck = new Vector();
// implement this s... 阅读全帖
k**f
发帖数: 372
43
来自主题: Programming版 - 包含指针的类和vector的问题

I'm not小猪 or thrust,but I think using vector is not necessary more
professional than using vector.
Do you know why your programs use vector instead of vector
? Is A a
base class with virtual function?
b***y
发帖数: 2799
44
来自主题: Programming版 - [合集] 一个vector的问题
☆─────────────────────────────────────☆
xubest (既飞之蜻蜓) 于 (Tue Feb 19 17:49:14 2008) 提到:
想要建立一个二维数组,其中的一维需要我输入之后就知道具体多大,且保持不表,另
一维则在运算过程中不断扩充。
比如:
int N;
cin>>N;
vector a[N];
for (int i=0; i {
for (int j=0; j<10; j++)
{
a[i].push_back(j);
}
}
这样的话,如果输入N=10, 那么数组a最后就是10X10的数组了。
但是我现在想知道能不能定个vector的指针?
比如
vector *a;
cin>>N;
a=new vector [N];
但是这样编译不通过。。。。
不知道什么办法改进?请有经验者指教,多谢!!!!
☆─────────────────────────────────────☆
kukutf (五脚蟹★酷酷豆腐) 于 (Tue Feb 19 18
d****n
发帖数: 130
45
来自主题: Programming版 - 如何把文件内容读到2D的vector里?
在文件里放着一个2D数组数据,想读到一个2D的vector里:
ifstream in("data.dat");
istream_iterator head(in);
istream_iterator tail(head);
vector > data;
for (int i = 0; i < x_size; ++i) {
head = tail;
advance(tail, y_size);
data.push_back(vector());
copy(head, tail, back_inserter(data.back()));
}
不work啊。
j***i
发帖数: 1278
46
比如 vector< vector > a;
b 是一个vector.
a.push_back(b) 编译不过
w*****3
发帖数: 101
47
来自主题: Programming版 - vector在constructor里初始化
class Foo{
public:
Foo(int capacity);
....
private:
vector _stack;
....
};//class Foo
Foo(int capacity){ //Foo1
//wrong, _stack still empty outside the constructor scope
vector_stack(capacity);
}
Foo(int capacity){ //Foo2
//right, _stack initialized
_stack = vector(capacity;
}
Questions:
why vector_stack(capacity); in the constructor Foo1 doesn't work
Thanks
w*****3
发帖数: 101
48
来自主题: Programming版 - C++ vector 到底能多大
郁闷死我了,help
一个简单的循环, 每次运算的结果存在一个vector里面,
程序在小数据的情况下没问题,
然后我定义一个
vector v(3000000000,false);
跑着跑着就当掉了,说write violation
我查了一下vector可以没有超过max_size
cout< 我的问题是:
1)如何知道这个vector是在哪分的空间,heap 还是 stack
2)是不是有什么参数可以调整程序可分配的空间
m*p
发帖数: 1331
49
【 以下文字转载自 JobHunting 讨论区 】
发信人: mbp (Mac Book Pro), 信区: JobHunting
标 题: java: use vector to shuffle a deck of Card 问题
发信站: BBS 未名空间站 (Thu Mar 3 00:40:48 2011, 美东)
要求用vector实现shuffle a deck of Card,如下:
public class Card {
private int value;
Card(int v) {
value = v;
}

public void print(){
System.out.print(value+";");
}
}
public class DeckShuffle {

private final int num;
Vector deck = new Vector();
// implement this s... 阅读全帖
s******y
发帖数: 28562
50
对于vector 和 insert的理解不是按大小而定的。
其实因为抗生素(或者其他什么用来做选择的)基因以及各种乱七八糟用
来扩展的因子等等都是在vector上的,所以没有连上vector的片断都不能
在细菌里面扩增。
所以包含抗生素和那些扩展因子的都是vector,再小也是。
不包含这些的就是insert, 再大也是
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)