【发布时间】:2016-04-14 03:37:02
【问题描述】:
我想创建一批随机大小 (10-1000) 的矩阵和随机数据。我需要以某种方式安排这批,以便我可以在以后的数据处理中使用它,所以它们需要一个一个地访问。
#include <stdio.h>
#include <assert.h>
#include <list>;
unsigned char* createAMatrix(int width,int hight){
unsigned char mat[width][hight];
unsigned char* ptr;
srand(100);
for(int row=0;row<hight;row++){
for(int col=0;col<width;col++){
mat[row][col]=rand();
}
}
ptr=&mat[0][0];
return ptr;
}
int main(int argc, char **argv)
{
std::list<unsigned char*> matList;
//create a batch of matrixes
int batchSize=1;
srand(100);
for(int k=0;k<batchSize;k++){
//set 10-1000 hight & width
int matWidth=rand()%990+10;
int matHight=rand()%990+10;
//create matrix
matList.push_back(createAMatrix(matWidth,matHight));
}
}
这是我到目前为止所拥有的,我无法确定解决此问题的最佳方法是指针还是其他方法?使用列表是存储它们的最佳方式吗?
顺便说一句,我知道代码中存在问题。它正在调试中。
【问题讨论】:
标签: c++ arrays database list pointers