void Test2()//PushFront PopFront Find { PSListNode ret = NULL; PSListNode pHead = NULL; InitList(&pHead); PushFront(&pHead,0); PushFront(&pHead,1); PushFront(&pHead,2); PushFront(&pHead,3); PushFront(&pHead,4); PrintList(&pHead); PopFront(&pHead); PopFront(&pHead); //PopFront(&pHead); //PopFront(&pHead); //PopFront(&pHead); //PopFront(&pHead); PrintList(&pHead); ret = Find(&pHead,2); if (ret == NULL) { printf("no find\n"); } else { printf("%d \n",ret->data); } }
Node<T> * List<T>::IntertBefore(Node<T> * inNode, const T &data) { if (first == inNode) { return PushFront(data); }// We are on the first node Node<T> *newNode = new Node<T>(data, nullptr, nullptr); newNode->next = inNode; newNode->prev = inNode->prev; inNode->prev->next = newNode; inNode->prev = newNode; return nullptr; }
void Test2() { Seq seq; InitSeqList(&seq); PushFront(&seq, 1); PushFront(&seq, 2); PushFront(&seq, 3); PushFront(&seq, 4); PushFront(&seq, 5); PopFront(&seq); PopFront(&seq); PopFront(&seq); PopFront(&seq); // PopFront(&seq); // PopFront(&seq); PrintSeqList(&seq); }
void test1() { LinkList list; InitLinkList(&list); PushBack(&list, 1); PushBack(&list, 2); PushBack(&list, 3); PushBack(&list, 4); PushBack(&list, 5); PopBack(&list); PopBack(&list); PopBack(&list); PrintList(&list); PushFront(&list, 6); PushFront(&list, 7); PushFront(&list, 8); PrintList(&list); PopFront(&list); PrintList(&list); DestoryLinkList(&list); PrintList(&list); }
void CardShuffler<Card>::operator()(Card** head) { //count the number of cards int size = 0; Card* it = *head; while (it) it = it->GetNext(), size++; //shuffle the cards Card* tmpHead = nullptr; while(size) { PushFront(&tmpHead, PopRandom(head, size)); size--; } *head = tmpHead; }
void *product(void *arg) { while(pthread_mutex_lock(&_lock)==0) {while(1) { pthread_mutex_lock(&lock); int data=rand()%1234; PushFront(head,data); printf("%x: %d\n",pthread_self(),data); pthread_cond_signal(&cond); pthread_mutex_unlock(&lock); pthread_mutex_unlock(&_lock); sleep(5); }} }
void DList::insert(int pos, DataType d) { Node *cur = _head; if (pos == 0) { PushFront(d); return; } while (pos -- >0) { if (cur == NULL) return; cur = cur->_next; } (cur->_prev)->_next = cur->_next; delete cur; cur = NULL; }
void *product1(void *arg) { while(pthread_mutex_lock(&_lock)==0) { while(1) { pthread_mutex_lock(&lock); int data=-1; PushFront(head,data); printf("pro1: %d\n",data); pthread_cond_signal(&cond); pthread_mutex_unlock(&lock); pthread_mutex_unlock(&_lock); sleep(5); } } }
void CodeList::InsertBefore(StmtBase *toInsert, StmtBase *stmt) { nbASSERT(stmt != NULL, "Trying to insert a null statement!"); nbASSERT(Head != NULL && Tail == NULL, "Empty List"); StmtBase *prevItem = stmt->Prev; if (prevItem == NULL) { PushFront(stmt); return; } toInsert->Next = stmt; stmt->Prev = toInsert; prevItem->Next = toInsert; toInsert->Prev = prevItem; NumStatements++; }
void ValuesTable::Move(const Interval &in) { if (in.End() < 0 || in.Start() >= (int)m_values.size()) { m_values.resize(0); m_values.resize(in.End() - in.Start() + 1); return; } while ((in.End() + 1) < (int)m_values.size()) PopBack(); for (int i = 0; i < in.Start(); ++i) PopFront(); for (int i = 0; i > in.Start(); --i) PushFront(); for (int i = m_values.size(); i <= in.End() - in.Start(); ++i) PushBack(); }
wxTarClassFactory::wxTarClassFactory() { if (this == &g_wxTarClassFactory) PushFront(); }
wxGzipClassFactory::wxGzipClassFactory() { if (this == &g_wxGzipClassFactory && wxZlibInputStream::CanHandleGZip()) PushFront(); }
void BidirBuffer::PushFront(BidirBuffer &src) { PushFront(src.Front(), src.Size()); }
void BidirBuffer::PushFront( byte val ) { PushFront(&val, 1); }
// Verify TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK. #include <type_traits> #include "test_workarounds.h" struct X { X(int) {} X(X&&) = default; X& operator=(X&&) = default; private: X(const X&) = default; X& operator=(const X&) = default; }; void PushFront(X&&) {} template<class T = int> auto test(int) -> decltype(PushFront(std::declval<T>()), std::true_type{}); auto test(long) -> std::false_type; int main() { #if defined(TEST_WORKAROUND_C1XX_BROKEN_ZA_CTOR_CHECK) static_assert(!decltype(test(0))::value, ""); #else static_assert(decltype(test(0))::value, ""); #endif }
void InsertAt(uword indx, T item) { PushFront(Item[indx]); Item[indx] = item; }
void LLBC_Array::PushFront(LLBC_Array::Iter it) { PushFront(*it); }
void StudentTests() { std::cout << "============================================================================" << std::endl; std::cout << "STUDENT TESTS" << std::endl; std::cout << "POPBACK TEST...\n" << std::endl; TrainCar* simple = NULL; PushBack(simple, TrainCar::MakeEngine()); PushBack(simple, TrainCar::MakePassengerCar()); PushBack(simple, TrainCar::MakePassengerCar()); PushBack(simple, TrainCar::MakeDiningCar()); PushBack(simple, TrainCar::MakePassengerCar()); PushBack(simple, TrainCar::MakeSleepingCar()); PrintTrain(simple); TrainCar* tmp = PopLastCar(simple); PrintTrain(simple); PrintTrain(tmp); PushFront(simple, tmp); PrintTrain(simple); SanityCheck(simple); std::cout << "\nPOPFRONT TEST... \n" << std::endl; TrainCar* simple2 = NULL; PushBack(simple2, TrainCar::MakeEngine()); PushBack(simple2, TrainCar::MakePassengerCar()); PushBack(simple2, TrainCar::MakePassengerCar()); PushBack(simple2, TrainCar::MakeDiningCar()); PushBack(simple2, TrainCar::MakePassengerCar()); PushBack(simple2, TrainCar::MakeSleepingCar()); PrintTrain(simple2); TrainCar* tmp2 = PopFrontCar(simple2); PrintTrain(simple2); PrintTrain(tmp2); PushFront(simple2, tmp2); PrintTrain(simple2); SanityCheck(simple2); std::cout << "\nPOP TEST" << std::endl; TrainCar* simple3 = NULL; PushBack(simple3, TrainCar::MakeEngine()); PushBack(simple3, TrainCar::MakePassengerCar()); PushBack(simple3, TrainCar::MakePassengerCar()); PushBack(simple3, TrainCar::MakeDiningCar()); PushBack(simple3, TrainCar::MakePassengerCar()); PushBack(simple3, TrainCar::MakeSleepingCar()); PrintTrain(simple3); int ID=simple3->getID(); TrainCar* tmp3 = PopCar(simple3, ID); PrintTrain(simple3); PrintTrain(tmp3); PushFront(simple3, tmp3); PrintTrain(simple3); SanityCheck(simple3); DeleteAllCars(simple); DeleteAllCars(simple2); DeleteAllCars(simple3); std::cout << "StudentTests complete" << std::endl; }