本文整理匯總了C++中TList::push_front方法的典型用法代碼示例。如果您正苦於以下問題:C++ TList::push_front方法的具體用法?C++ TList::push_front怎麽用?C++ TList::push_front使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類TList
的用法示例。
在下文中一共展示了TList::push_front方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C++代碼示例。
示例1: DoTestFrontBack
std::string DoTestFrontBack(size_t n) {
TCounter::Reset();
{
constexpr int M = 10;
TCounter data[M];
TList<TCounter, std::allocator<TCounter>> lst;
for (size_t i = 0; i < n; ++i) {
lst.push_back(TCounter(data[i % M]));
}
if (lst.size() != n)
return "lst.size(): wrong answer";
if (lst.back().GetData() != data[(n + M - 1) % M].GetData())
return "lst.back(): wrong answer";
if (lst.front().GetData() != data[0].GetData())
return "lst.front(): wrong answer";
while (!lst.empty())
lst.pop_back();
for (size_t i = 0; i < n; ++i) {
lst.push_front(TCounter(data[i % M]));
}
if (lst.size() != n)
return "lst.size(): wrong answer";
if (lst.front().GetData() != data[(n + M - 1) % M].GetData())
return "lst.back(): wrong answer";
if (lst.back().GetData() != data[0].GetData())
return "lst.front(): wrong answer";
while (!lst.empty())
lst.pop_front();
}
TCounter::CheckTotalOperationsCount(n * 10 + 100, n + 100);
return TCounter::GetAllErrors();
}
示例2: 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;
}