void Test1() { Seq seq; InitSeqList(&seq); PushBack(&seq, 1); PushBack(&seq, 2); PushBack(&seq, 3); PushBack(&seq, 4); PushBack(&seq, 5); PopBack(&seq); PopBack(&seq); PrintSeqList(&seq); }
void DList::Remove(DataType d) { Node *cur = _head; int ret = Find(d); if (ret == 0) { PopFront(); return; } while (ret--) { if (cur == NULL) return; cur = cur->_next; } if (cur != NULL) { if (cur == _tail) { PopBack(); } else { Node *tmp = cur; (cur->_prev)->_next = cur->_next; delete tmp; tmp = NULL; } } }
descriptor_allocation_t DescriptorAllocator::Allocate(u32 num) { Check(num < BlockSize); auto bucket = find_log_2(num); auto m = pad_pow_2(num); u32 heapOffset = 0; if (Size(FreeRanges[bucket])) { heapOffset = Back(FreeRanges[bucket]).heap_offset; PopBack(FreeRanges[bucket]); } else { if (SuballocatedBlock[bucket] == NULL_BLOCK) { SuballocatedBlock[bucket] = AllocateBlock(); } heapOffset = SuballocatedBlock[bucket] * BlockSize + Blocks[SuballocatedBlock[bucket]].next_allocation_offset; Blocks[SuballocatedBlock[bucket]].next_allocation_offset += m; if (Blocks[SuballocatedBlock[bucket]].next_allocation_offset == BlockSize) { SuballocatedBlock[bucket] = NULL_BLOCK; } } descriptor_allocation_t allocation = {}; allocation.allocator = this; allocation.heap_offset = heapOffset; allocation.size = num; return allocation; }
void Test1()//PushBack PopBack { PSListNode pHead = NULL; InitList(&pHead); PushBack(&pHead,0); PushBack(&pHead,1); PushBack(&pHead,2); PushBack(&pHead,3); PushBack(&pHead,4); PrintList(&pHead); PopBack(&pHead); PopBack(&pHead); PrintList(&pHead); }
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* CMyList::PopIndex(int idx) { if (idx <= 0) { return PopHead(); } if (idx >= m_NodeCount - 1) { return PopBack(); } Lock(); if (isEmpty()) { UnLock(); return NULL; } void *tagRet = NULL; MYLIST_NODE *pPrev = NULL, *pCurr = m_MyListHead; for (int i=0; i<idx; i++) { if (pCurr) { pPrev = pCurr; pCurr = pCurr->pNext; } } if (pPrev) { tagRet = pCurr->pData; pPrev->pNext = pCurr->pNext; FreeMem(pCurr); } else { tagRet = m_MyListHead->pData; FreeMem(m_MyListHead); m_MyListHead = NULL; m_MyListTail = NULL; } m_NodeCount--; UnLock(); return tagRet; }
void Datum::Clear() { throwIfExternal(); if (mContainer.voidPointer == nullptr) return; while (!IsEmpty()) { PopBack(); } free(mContainer.voidPointer); mCapacity = 0; mContainer.voidPointer = nullptr; }
TLFObject* TLFList::Pop(TLFObject* object) { if (m_headNode == NULL) return NULL; if (First() == object) { // удаляем первый элемент. TLFListNode* node = m_headNode->NextNode(); delete m_headNode; m_headNode = node; if (node != NULL) return node->GetElement(); else return NULL; } else if (Last() == object) { PopBack(); return NULL; } else { TLFListNode* node = m_headNode; TLFListNode* node1 = m_headNode->NextNode(); if (node1 == NULL) return NULL; while (node1->NextNode() != NULL) { if (node1->GetElement() == object) { node->SetNextNode(node1->NextNode()); delete node1; if (node->NextNode() != NULL) return node->NextNode()->GetElement(); else return NULL; } node = node1; node1 = node1->NextNode(); } } return NULL; }
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(); }
int solve() { int ans = N; u32 top = 1 << M; for (int n = 1; n <= M; ++n) { for (u32 b = init_popcount(n); b < top; b = next_popcount(b)) { i64 _lcm = 1; for (u32 it = b; it; PopBack(it)) { u32 bit = Back(it); int idx = pos[bit]; _lcm = lcm(_lcm, ms[idx]); } int x = N / _lcm; ans = n % 2 == 0 ? ans + x : ans - x; } } return ans; }
void Rotate(int nRotate) { // quick fix // need optimization if(!Empty()){ if(auto nCount = std::abs(nRotate)){ if(nRotate > 0){ for(auto nIndex = 0; nIndex < nCount; ++nIndex){ auto stHead = Head(); PopHead(); PushBack(stHead); } }else{ for(auto nIndex = 0; nIndex < nCount; ++nIndex){ auto stBack = Back(); PopBack(); PushHead(stBack); } } } } }