本文整理汇总了C++中List::AddToBack方法的典型用法代码示例。如果您正苦于以下问题:C++ List::AddToBack方法的具体用法?C++ List::AddToBack怎么用?C++ List::AddToBack使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类List
的用法示例。
在下文中一共展示了List::AddToBack方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeDuplicates
List<T> removeDuplicates(List<T> l, compare<T> comp) {
List<T> removed;
for (int i = 0; i < l.length(); ++i) {
T val = l[i];
bool found = false;
for (int j = 0; j < removed.length(); ++j) {
if (comp(removed[j], val))
found = true;
}
if (!found)
removed.AddToBack(val);
}
return removed;
}
示例2: main
int main() {
List<int> l;
l.AddToBack(1);
l.AddToBack(2);
l.AddToBack(3);
l.AddToBack(4);
l.AddToBack(5);
std::cerr << "l: ";
int size = l.length();
for (int i = 0; i < size; ++i)
std::cerr << " " << l[i];
std::cerr << std::endl;
List<int> copy(l);
std::cerr << "copy: ";
size = copy.length();
for (int i = 0; i < size; ++i)
std::cerr << copy[i] << " ";
std::cerr << std::endl;
List<int> assigned = l;
std::cerr << "assigned: ";
size = assigned.length();
for (int i = 0; i < size; ++i)
std::cerr << assigned[i] << " ";
std::cerr << std::endl;
for (int i = 0; i < 2; ++i) {
int front = l.RemoveFromFront();
std::cerr << "removed " << front << " ";
}
std::cerr << std::endl;
std::cerr << "l: ";
for (int i = 0; i < l.length(); ++i)
std::cerr << l[i] << " ";
std::cerr << std::endl;
std::cerr << "copy: ";
for (int i = 0; i < copy.length(); ++i)
std::cerr << copy[i] << " ";
std::cerr << std::endl;
std::cerr << "assigned: ";
for (int i = 0; i < assigned.length(); ++i)
std::cerr << assigned[i] << " ";
std::cerr << std::endl;
// =======================================
// Problem 2
List<int> dups;
dups.AddToBack(1);
dups.AddToBack(2);
dups.AddToBack(3);
dups.AddToBack(4);
dups.AddToBack(2);
dups.AddToBack(3);
dups.AddToBack(3);
compare<int> f;
List<int> removed = removeDuplicates(dups, f);
std::cerr << "removed: ";
for (int i = 0; i < removed.length(); ++i)
std::cerr << removed[i] << " ";
std::cerr << std::endl;
return 0;
}