当前位置: 首页>>代码示例>>C++>>正文


C++ List::AddToBack方法代码示例

本文整理汇总了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;
}
开发者ID:dtg3,项目名称:scratchpad,代码行数:18,代码来源:singly-linked-list.cpp

示例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;
}
开发者ID:dtg3,项目名称:scratchpad,代码行数:74,代码来源:singly-linked-list.cpp


注:本文中的List::AddToBack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。