Beispiel #1
0
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;
}
 TList(const TList<T, Allocator> &list) {
     begin_ = nullptr;
     end_ = nullptr;
     size_ = 0;
     for (TConstListIterator it = list.begin(); it != list.end(); ++it) {
         push_back(*it);
     }
 }
Beispiel #3
0
Datei: 03.cpp Projekt: filaPro/my
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();
}
Beispiel #4
0
be_ArgumentList::be_ArgumentList(const TList<be_argument*>& oldlist)
{
   TList<be_argument*>::iterator iter;

   for (iter = oldlist.begin(); iter != oldlist.end(); ++iter)
   {
      const be_argument& arg = *(*iter);
      push_back(be_Argument(arg));
   }
}
 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();
     }
 }
Beispiel #6
0
int TimerMaster::CascadeTimers(TimerVec *v, int index) {
  TList *l = &(*v)[index];
  for (TList::iterator it = l->begin();
       it != l->end();) {
    TimerSlot *s = &*it;
    ++it;
    s->unlink();
    InternalAddTimer(s, s->weak_timer, s->jiffies);
  }
  CHECK(l->empty());
  return index;
}
Beispiel #7
0
void TimerMaster::DestroyAllTimers() {
  for (int i = 0; i < arraysize(vecs_); ++i) {
    for (int j = 0; j < kTVSize; ++j) {
      TList *l = &vecs_[i][j];
      for (TList::iterator it = l->begin(); it != l->end();) {
        TimerSlot *s = &*it;
        ++it;
        delete s;
      }
    }
  }
}
 bool operator ==(const TList<T, Allocator> &list) const {
     if (size_ != list.size()) {
         return false;
     }
     TConstListIterator first = begin();
     TConstListIterator second = list.begin();
     for (; first != end(); ++first, ++second) {
         if (*first != *second) {
             return false;
         }
     }
     return true;
 }
Beispiel #9
0
void TimerMaster::Update(int jiffies) {
  CHECK_GE(jiffies, timer_jiffies_);
  TimerVec &v0 = vecs_[0];
  while (jiffies - timer_jiffies_ >= 0) {
    vector<pair<TimerSlot*, boost::shared_ptr<Timer> > > timers;
    {
      boost::mutex::scoped_lock lock(mutex_);
      const int index = timer_jiffies_ & kTVMask;
      if (!index && !CascadeTimers(&vecs_[1], INDEX(1)) &&
          !CascadeTimers(&vecs_[2], INDEX(2))) {
        CascadeTimers(&vecs_[3], INDEX(3));
      }
      TList *l = &v0[index];
      for (TList::iterator it = l->begin();
           it != l->end();) {
        TimerSlot *s = &*it;
        ++it;
        s->unlink();
        boost::weak_ptr<Timer> weak_timer = s->weak_timer;
        boost::shared_ptr<Timer> timer = weak_timer.lock();
        if (weak_timer.expired()) {
          delete s;
          continue;
        }
        timers.push_back(make_pair(s, timer));
      }
    }
    const int old_timer_jiffies = timer_jiffies_;
    ++timer_jiffies_;
    for (vector<pair<TimerSlot*, boost::shared_ptr<Timer> > >::iterator it =
         timers.begin(); it != timers.end(); ++it) {
      it->second->Expired();
    }
    {
      for (int i = 0; i < timers.size(); ++i) {
        TimerSlot *s = timers[i].first;
        boost::shared_ptr<Timer> timer = timers[i].second;
        if (timer->period()) {
          boost::mutex::scoped_lock lock(mutex_);
          InternalAddTimer(s, timer, timer->timeout() + old_timer_jiffies);
        } else {
          delete s;
        }
      }
    }
  }
}