本文整理汇总了C++中LList::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ LList::erase方法的具体用法?C++ LList::erase怎么用?C++ LList::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LList
的用法示例。
在下文中一共展示了LList::erase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeRow
/*Function for removing the row
The spreadsheet is iterated till the position where the row is to be removed. remove() is called to
remove a row at the row value position in user input. If last row is removed, tail pointer is adjusted
and made to point the row above it. If first row (0th row) is removed, head pointer is adjusted adjusted
to point next row.
*/
void removeRow(LList<LList<Cell*>>& rows, int removeRowValue){
int h = 0; //increments to track the height or row value
LList<LList<Cell*>>::iterator I = rows.begin();
for (LList<LList<Cell*>>::iterator I = rows.begin(); I != rows.end(); I++){
/*Remove a cell on the position if the value of the rows iterated equals to the value of row
in the user input where the row is to be removed.
*/
if (h == removeRowValue){
I = rows.erase(I, removeRowValue, height);
}
h++;
}
//decrease the height of the spreadsheet by one if a row is removed
height -= 1;
}
示例2: main
int main()
{
LList<int> llist;
LList<int>::iterator it = llist.begin();
LList<int>::iterator it2 = llist.end();
it2 = LList<int>::iterator(it);
#if 1
it = llist.insert(it,1);
it = llist.insert(it,2);
it = llist.insert(it,3);
it = llist.begin();
cout<<"--------insert-------------"<<endl;
for(;it != llist.end();it++)
cout<<*it<<endl;
llist.clear();
llist.push_back(11);
llist.push_back(12);
llist.push_back(13);
llist.erase(llist.begin());
cout<<"--------push_back-------------"<<endl;
for(it=llist.begin();it != llist.end();it++)
cout<<*it<<endl;
llist.clear();
cout<<"--------size-------------"<<llist.size()<<endl;
llist.push_back(14);
llist.push_back(15);
llist.push_back(16);
for(it=llist.begin();it != llist.end();it++)
cout<<*it<<endl;
cout<<"--------transfer-------------"<<llist.size()<<endl;
LList<int>::iterator first= ++llist.begin();
LList<int>::iterator last= llist.end();
llist.transfer(++llist.begin(),++first,last);
for(it=llist.begin();it != llist.end();it++)
cout<<*it<<endl;
cout<<"--------reverse-------------"<<llist.size()<<endl;
llist.reverse();
for(it=llist.begin();it != llist.end();it++)
cout<<*it<<endl;
#endif
return 0;
}
示例3: main
int main() {
LList L;
srand(77);
unsigned int r, e, pos;
r = rand() % 12;
cout << "Inserting " << r << " elements to the list...." << endl;
for (int i=0; i<r; i++) {
e = rand()%100;
cout << "Inserting " << e << " at position 0" << endl;
L.insert(e,0);
}
cout << "Contents of the list: " << L << endl << endl;
r = rand() % r;
cout << "Now erasing elements from random positions ...." << endl;
for (int i=0; i<r; i++) {
pos = rand()% L.getSize();
cout << "Erasing from position " << pos << endl;
L.erase(pos);
cout << "Contents of the list: " << L << endl;
}
cout << endl;
/***** Uncomment after you have implemented the push function *
e = rand()%100;
cout << "Now lets push a " << e <<" into the list..." << endl;
cout << "The list is " << L.push(e) << " long " << endl;
cout << "And contains: " << L << endl << endl;
************************************************************/
/***** Uncomment after you have implemented the shift function *
cout << "I have removed the element from the front of the list: "
<< L.shift() << endl;
cout << "List now contains: " << L << endl << endl;
************************************************************/
/***** Uncomment after you have implemented the pop function *
cout << "Removing element from the front of the list using pop() " << endl;
cout << "The element is: " << L.pop() << endl;
cout << "List now contains: " << L << endl << endl;
// Error del profe! No descomente
// pos = rand() % L.getSize();
// cout << "Removing element from pos " << pos
// << " of the list using pop(" << pos << ")" << endl;
// cout << "The element is: " << L.pop(pos) << endl;
// cout << "List now contains: " << L << endl << endl;
************************************************************/
/***** Uncomment after you have implemented the splice function *
r = rand() % (L.getSize()/2);
r = 9;
pos = rand() % (L.getSize()/2);
cout << "Using the splice function to remove " << r
<< " elements starting at position " << pos << endl;
cout << "The removed elements are: " << L.splice(pos, r) << endl;
cout << "After splice, the List:" << L << endl << endl;
************************************************************/
/***** Uncomment after you have implemented the join function
cout << "The following is a string of all elements, using join:" << endl;
cout << L.join("-") << endl << endl;
************************************************************/
cout << endl;
}