本文整理汇总了C++中TList::erase方法的典型用法代码示例。如果您正苦于以下问题:C++ TList::erase方法的具体用法?C++ TList::erase怎么用?C++ TList::erase使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TList
的用法示例。
在下文中一共展示了TList::erase方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
int i, x;
TList<int> L;
for (i = 0; i < 10; ++i)
{
x = i*i;
L.push_front(x); // mit Quadratzahlen füllen
}
TList<int>::Iterator ListIter(L);
cout << "*ListIter = " << *ListIter << endl;
cout << "ListIter++;" << endl;
ListIter++;
cout << "*ListIter = " << *ListIter << endl;
// 36 löschen, falls vorhanden
while(ListIter++ != L.end())
if (*ListIter == 36)
{
cout << *ListIter << " wird geloescht\n";
L.erase(ListIter);
cout << *ListIter
<< " an aktueller Position\n";
break;
}
int target = 3;
int count = 0;
TList<int>::Iterator it = L.begin();
while (it != L.end()) {
if (count == target) {
std::cout << "bam" << *it << std::endl;
}
count++;
it++;
}
//for (TList<int>::Iterator iter = L.begin(); iter != L.end(); i++) {
// std::cout << *iter << std::endl;
//}
//TList<int>::Iterator it = L.begin();
//while (it != L.end()) {
// std::cout << *it << std::endl;
// it++;
//}
for (TList<int>::Iterator itt = L.begin(); itt != L.end(); ++itt) {
std::cout << *itt << " ";
}
return 0;
}
示例2: merge
void merge(TList<T, Allocator> &list) {
if (&list == this) {
return;
}
TListIterator firstIter = begin();
TListIterator secondIter = list.begin();
while (firstIter != end() && secondIter != list.end()) {
if (*firstIter < *secondIter) {
++firstIter;
} else {
insert(firstIter, *secondIter);
list.erase(secondIter);
secondIter = list.begin();
}
}
while (secondIter != end()) {
insert(firstIter, *secondIter);
list.erase(secondIter);
secondIter = list.begin();
}
}
示例3: DoTestInsertRemoveEmpty
std::string DoTestInsertRemoveEmpty(size_t n) {
TCounter::Reset();
{
TList<TCounter, std::allocator<TCounter>> lst;
for (size_t i = 0; i < n; ++i) {
TList<TCounter, std::allocator<TCounter>>::iterator it = lst.begin();
for (size_t j = 0; j < i / 2; ++j)
++it;
lst.insert(it, TCounter());
}
if (lst.size() != n)
return "lst.size(): wrong answer";
while (!lst.empty())
lst.erase(lst.begin());
}
TCounter::CheckTotalOperationsCount(n * 5 + 100, n + 100);
return TCounter::GetAllErrors();
}