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


C++ TList::push_back方法代码示例

本文整理汇总了C++中TList::push_back方法的典型用法代码示例。如果您正苦于以下问题:C++ TList::push_back方法的具体用法?C++ TList::push_back怎么用?C++ TList::push_back使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TList的用法示例。


在下文中一共展示了TList::push_back方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoTestReverseUniqSort

std::string DoTestReverseUniqSort(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        TList<int> lint;
        for (size_t i = 0; i < 2 * n; ++i) {
            lst.push_back(TCounter());
            lint.push_back(i / 2);
        }
        lst.reverse();
        lint.unique();
        if (lint.size() != n)
            return "lint.uniq(): wrong answer";
        lint.reverse();
        TList<int>::const_iterator it = lint.cbegin();
        for (size_t i = 0; i < n; ++i, ++it)
            if (*it != n - i - 1)
                return "lint.reverse(): wrong answer";
        lint.sort();
        it = lint.cbegin();
        for (size_t i = 0; i < n; ++i, ++it)
            if (*it != i)
                return "lint.sort(): wrong answer";
    }
    TCounter::CheckTotalOperationsCount(n * 10 + 100, 2 * n + 100);
    return TCounter::GetAllErrors();
}
开发者ID:filaPro,项目名称:my,代码行数:27,代码来源:03.cpp

示例2: DoTestSplice

std::string DoTestSplice(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        for (size_t i = 0; i < n; ++i) {
            lst.push_back(TCounter());
        }
        TList<TCounter, std::allocator<TCounter>> lst1;
        for (size_t i = 0; i < n; ++i) {
            lst1.push_back(TCounter());
        }
        TList<TCounter, std::allocator<TCounter>>::iterator from = lst1.begin(), to = lst1.end();
        ++from;
        --to;
        lst.splice(lst.end(), lst1, from, to);
        if (lst.size() != 2 * n - 2 || lst1.size() != 2)
            return "lst.splice() or lst.size(): wrong answer";
        lst.resize(n);
        if (lst.size() != n)
            return "lst.resize(): wrong answer";
        lst1.splice(lst1.end(), lst);
        if (lst1.size() != n + 2 || lst.size() != 0)
            return "lst.splice() or lst.size(): wrong answer";
    }
    TCounter::CheckTotalOperationsCount(n * 10 + 100, n * 2 + 100);
    return TCounter::GetAllErrors();
}
开发者ID:filaPro,项目名称:my,代码行数:27,代码来源:03.cpp

示例3: 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();
}
开发者ID:filaPro,项目名称:my,代码行数:32,代码来源:03.cpp

示例4: DoTestMove

std::string DoTestMove(size_t n) {
    TCounter::Reset();
    {
        TList<TCounter, std::allocator<TCounter>> lst;
        for (size_t i = 0; i < n; ++i) {
            lst.push_back(TCounter());
        }
        TList<TCounter> mv = std::move(lst);
        lst.swap(mv);
    }
    TCounter::CheckTotalOperationsCount(n * 5 + 100, n + 100);
    return TCounter::GetAllErrors();
}
开发者ID:filaPro,项目名称:my,代码行数:13,代码来源:03.cpp

示例5: InternalAddTimer

void TimerMaster::InternalAddTimer(
    TimerSlot *slot,
    boost::weak_ptr<Timer> weak_timer,
    int jiffies) {
  int i = 0;
  int idx  = jiffies - timer_jiffies_;
  TList *v = NULL;
  int expires = jiffies;
  uint64 upper = 1;
  for (int i = 0; i < arraysize(vecs_); ++i) {
    upper <<= kTVBits;
    if (idx < upper) {
      int j = expires & kTVMask;
      v = &vecs_[i][j];
      break;
    }
    expires >>= kTVBits;
  }
  CHECK(v != NULL);
  slot->weak_timer = weak_timer;
  slot->jiffies = jiffies;
  v->push_back(*slot);
}
开发者ID:0xec,项目名称:server1,代码行数:23,代码来源:timer_master.cpp


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