예제 #1
0
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);
}
예제 #2
0
파일: DList.cpp 프로젝트: ellerymo/MyCpp
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;
		}
	}
}
예제 #3
0
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;
}
예제 #4
0
파일: test.c 프로젝트: XHXaiXXR/code
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);
}
예제 #5
0
파일: test.c 프로젝트: clearoff/learngit
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);
}
예제 #6
0
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;
}
예제 #7
0
	void Datum::Clear()
	{
		throwIfExternal();
		
		if (mContainer.voidPointer == nullptr)
			return;

		while (!IsEmpty())
		{
			PopBack();
		}

		free(mContainer.voidPointer);

		mCapacity = 0;
		mContainer.voidPointer = nullptr;
	}
예제 #8
0
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;
}
예제 #9
0
파일: draw.cpp 프로젝트: cyclefusion/szarp
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();
}
예제 #10
0
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;
}
예제 #11
0
파일: cachequeue.hpp 프로젝트: etorth/mir2x
        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);
                        }
                    }
                }
            }
        }