本文整理汇总了C++中TwoDArray::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ TwoDArray::insert方法的具体用法?C++ TwoDArray::insert怎么用?C++ TwoDArray::insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TwoDArray
的用法示例。
在下文中一共展示了TwoDArray::insert方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
TEST(insert, stringTest) {
int r = 10;
int c = 10;
TwoDArray<string>* a = new TwoDArray<string>(r, c);
a->insert(0, 0, "hey");
a->insert(0, 9, "whats");
a->insert(9, 9, "up");
a->insert(4, 4, "yooooooooooo");
delete a;
}
示例2:
TEST(TwoDArray, Print) {
TwoDArray<int>* newArray = new TwoDArray<int>(10,10,0);
newArray->insert(1,2,1);
newArray->insert(9,8,2);
newArray->insert(7,2,3);
newArray->insert(6,4,4);
newArray->insert(0,8,5);
newArray->print();
delete newArray;
}
示例3:
TEST(TwoDArrayTest, insert) {
TwoDArray<int>* td = new TwoDArray<int>(10, 10, 0);
td->insert(5, 4, 10);
td->insert(5, 5, 9);
td->insert(5, 6, 8);
EXPECT_EQ(10, td->access(5, 4));
EXPECT_EQ(8, td->access(5, 6));
delete td;
}
示例4:
TEST(TwoDArrayTest, InsertInt) {
TwoDArray<int>* tDInt = new TwoDArray<int>(3, 3, 0);
for (int i=0; i < 3; i++) {
tDInt->insert(i, i, 3);
}
EXPECT_EQ(3, tDInt->access(1, 1));
delete tDInt;
}
示例5:
TEST(arrayTest, getNumRows) {
TwoDArray<int>* i = new TwoDArray<int>(5, 5, 0);
TwoDArray<double>* d = new TwoDArray<int>(6, 5, 0);
TwoDArray<std::string>* s = new TwoDArray<std::string>(10, 5, "o");
i->insert(2, 2, 7);
d->insert(4, 4, 3.145);
s->insert(0, 0, "Hello");
EXPECT_EQ(5, i->getNumRows());
EXPECT_EQ(6, d->getNumRows());
EXPECT_EQ(10, s->getNumRows());
delete i;
delete d;
delete s;
}
示例6:
void AVLTree<T>::visualPrint(T def, T leftLeg, T rightLeg) {
//make a Queue of globs, push in root at 0, 0
list<Glob<T>*> q;
int level=0; int spread=0;
Glob<T>* root_glob = new Glob<T>(*root, level, spread);
q.push_back (root_glob);
//make 2d vector for glob coordinates, spread is width, level is depth
int s; int l;
TwoDArray<T>* tda = new TwoDArray<T>(8, 15, def);
int spread_middle = 7;
//begin level order traversal of AVLTree and insert into tda
Node<T>* curr_node;
while (!(q.empty())) {
Glob<T>* curr_glob = q.front();
curr_node = curr_glob->getNodePointer();
if (curr_node->getLeftChild()!=0) {
//get level, spread for left node and make a glob
level = (curr_glob->getLevel())+2;
spread = (curr_glob->getSpread())-2;
Glob<T>* new_glob_left = new Glob<T>(*(curr_node->getLeftChild()), level, spread);
q.push_back (new_glob_left);
//insert left leg into tda
tda->insert(level-1, spread_middle+spread+1, leftLeg);
}
if (curr_node->getRightChild()!=0) {
level=(curr_glob->getLevel())+2;
spread = (curr_glob->getSpread())+2;
Glob<T>* new_glob_right = new Glob<T>(*(curr_node->getRightChild()), level, spread);
q.push_back (new_glob_right);
//insert right leg tda
tda->insert(level-1, spread_middle+spread-1, rightLeg);
}
if (curr_node!=0) {
l = curr_glob->getLevel();
s = curr_glob->getSpread();
tda->insert(l, spread_middle+s, curr_glob->getNodePointer()->getValue());
}
q.pop_front();
}
tda->print();
delete tda;
delete root_glob;
}
示例7: main
int main(){
TwoDArray<int>* newArray = new TwoDArray<int>(10, 10, 0);
newArray->insert(1,1,5);
cout << newArray->access(1,1) << endl;
newArray->remove(1,1);
cout << newArray->access(1,1) << endl;
newArray->print();
delete newArray;
TwoDArray<std::string>* nextArray = new TwoDArray<std::string>(5,5, "hi");
nextArray->insert(2,2, "bye");
nextArray->print();
delete nextArray;
}