ToolList::~ToolList() { // Call destructors on all objects in the list ToolListItem *Item = (ToolListItem *) RemoveHead(); while (Item != NULL) { // Delete the list item delete Item; // Try the next item Item = (ToolListItem *) RemoveHead(); } }
void DLList::RemoveTail() { if (head_ != NULL) { if (head_ -> next_node() == NULL) { RemoveHead(); } else { DLNode* temp = NULL; DLNode* iterator = head_; while (iterator -> next_node() != NULL) { temp = iterator; iterator = iterator -> next_node(); } temp -> set_next_node(NULL); tail_ = temp; delete iterator; temp = NULL; iterator = NULL; size_--; } } }
///////////////////////////////////////////////////////////////////////////// // Note: The undo list must be maintained as a string of undos // You cannot, for example, log an undo event and then decide to // to skip a few. To skip, the entire log must be deleted. // The invoking routines typically accept a NULL undo description // to indicate continuation; to stop undo, destroy the chain and // call with a NULL, thus not creating an undo event. ///////////////////////////////////////////////////////////////////////////// POSITION CUndLst::CreUndEvt (CString csDesStr, CUndSta *pNewSta) { ///////////////////////////////////////////////////////////////////////// // Delete tail of undo chain ///////////////////////////////////////////////////////////////////////// while (!IsEmpty() && (m_vpUndPos != m_olUndLst.GetTailPosition())) RemoveTail(); ///////////////////////////////////////////////////////////////////////// // Return NULL if undo has been inhibited ///////////////////////////////////////////////////////////////////////// if (!m_usUndMax) return (NULL); ///////////////////////////////////////////////////////////////////////// // Delete head to enforce maximum undo count; leave room for next ///////////////////////////////////////////////////////////////////////// while ((WORD) m_olUndLst.GetCount() >= m_usUndMax) RemoveHead(); ///////////////////////////////////////////////////////////////////////// // Find previous files 3 digit extension and increment ///////////////////////////////////////////////////////////////////////// WORD usNxtExt = IsEmpty() ? 0 : GetTail()->GetSeqNum() + 1; ///////////////////////////////////////////////////////////////////////// // Add new undo file ///////////////////////////////////////////////////////////////////////// m_vpUndPos = m_olUndLst.AddTail (new CUndEvt (usNxtExt, m_csTmpPfx, csDesStr, pNewSta)); return (m_vpUndPos); }
bool SLList::RemoveFirstOccurence(int data) { if(head_) //if there is a list { if(head_->contents() == data) //if the data is same as head { RemoveHead(); return true; } SLNode* prev = head_; //assign node to head_ SLNode* current = head_->next_node(); //assign current to node after head while(current) //while current is not NULL { if(current->contents() == data) //if current = to data { prev->set_next_node(current->next_node()); //prev points to the node after current if(current == tail_) //if current = tail, tail assigned to prev { tail_ = prev; } current = NULL; //dereference current delete current; //delete current size_--; //now we minus the size return true; } prev = current; //these traverse prev before current current = current->next_node(); } } else { return false; } }
void GSRasterizerList::FreeRasterizers() { while(!IsEmpty()) { delete RemoveHead(); } }
void SLList::Clear() { while (size_ != 0) { RemoveHead(); } }
void SLList::RemoveTail() { if (head_ != NULL) { if (head_ -> next_node() == NULL) { RemoveHead(); } else { SLNode *temp = NULL; SLNode *temp2 = head_; while (temp2 -> next_node() != NULL) { temp = temp2; temp2 = temp2 -> next_node(); } temp -> set_next_node(NULL); tail_ = temp; delete temp2; temp = NULL; temp2 = NULL; size_--; } } }
void SLList::Clear() //clears all data contents and nodes from list { while(head_) //calls the remove head function and cycles until there is now more contents { RemoveHead(); } !tail_; //sets tail to NULL }
void SLList::Clear() { head_ = NULL; tail_ = NULL; size_ = 0; while(head_ != NULL) { RemoveHead(); } }
CAutoPtr<Packet> CPacketQueue::Remove() { CAutoLock cAutoLock(this); ASSERT(__super::GetCount() > 0); CAutoPtr<Packet> p = RemoveHead(); if(p) m_size -= p->GetDataSize(); return p; }
void CaReplicationItemList::MyRemoveAll() { CaReplicationItem* pItem ; while (!IsEmpty()) { pItem = RemoveHead(); delete pItem; } }
CVwsEventQueue::~CVwsEventQueue() { do { delete Head(); } while (RemoveHead() == KErrNone); }
//clears the entire contents of the list, freeing all memory associated with all nodes void DLList::Clear() { while (head_ != NULL) { RemoveHead(); } tail_ = NULL; }
void CStrings::RemoveNodes() { while (first_node) { RemoveHead(); } last_node = NULL; num = 0; }
bool DLList::RemoveFirstOccurence(int remove_node) { DLNode *temp = NULL; //creates a temp pointer to hold the node to be deleted DLNode *iterator = head_; //creates an iterator and makes it point to head_ DLNode *iterator2 = NULL; //second iterator to trail behind the first iterator while(iterator != NULL) { if((iterator -> contents()) == remove_node) { if(iterator2 == NULL) { RemoveHead(); return true; } else if((iterator -> next_node()) == NULL) { RemoveTail(); return true; } else { temp = iterator; //points to the node that will be deleted iterator = iterator -> next_node(); //iterator points to the node after the one to be deleted iterator2 -> set_next_node(iterator); //iterator2's node sets the next node to iterator's node, skipping over the soon to be deleted node iterator -> set_previous_node(iterator2); //iterator's node sets the previous node to iterator2's node delete temp; //deletes the node temp = NULL; //sets temp to NULL size_--; //size of linked list decreases return true; } } else { iterator2 = iterator; iterator = iterator -> next_node(); } } return false; }
/** * clears the entire contents of the list, * freeing all memory associated with all nodes */ void SLList::Clear() { while (head_ != NULL) { RemoveHead(); } delete head_; head_ = NULL; tail_ = NULL; }
void SLList::Clear() { while (head_ != NULL) //checks for head contents in a loop-continues until list is empty { RemoveHead(); //removes head only if head exists } tail_ = NULL; //handles tail // (*MODIFY*) //clears the entire contents of the list, // freeing all memory associated with all nodes // (*NEW*) - sets tail_ to NULL }
int main (int argc, char* argv[]) { int dataInt[] = {1, 2, 3, 4, 5}; CSinglyListNode* head = CreateTestList(dataInt, 5); PrintList(head); // RemoveHead RemoveHead(&head); PrintList(head); RemoveHead(&head); PrintList(head); RemoveHead(&head); PrintList(head); RemoveHead(&head); PrintList(head); RemoveHead(&head); PrintList(head); RemoveHead(&head); PrintList(head); std::cout << "DeleteList..." << std::endl; DeleteList(&head); std::cout << "head now : " << head << std::endl; PrintList(head); std::cout << "bye" << std::endl; return 0; }
CHXList::~CHXList(void) { HX_ASSERT_VALID_PTR(this); while (! IsEmpty()) { IUnknown* punkItem = RemoveHead(); HX_ASSERT(punkItem != NULL); HX_RELEASE(punkItem); } HX_RELEASE(m_pFastAlloc); }
static void moveToWaste(LexizeData *ld, ParsedLex *stop) { bool go = true; while (ld->towork.head && go) { if (ld->towork.head == stop) { ld->curSub = stop->next; go = false; } RemoveHead(ld); } }
float CNPC_PoisonZombie::GetHitgroupDamageMultiplier(int iHitGroup, const CTakeDamageInfo &info) { switch (iHitGroup) { case HITGROUP_HEAD: { int HeadshotRandom = random->RandomInt(0, 6); if (!(g_Language.GetInt() == LANGUAGE_GERMAN || UTIL_IsLowViolence())) { if (!m_fIsHeadless && HeadshotRandom == 0 && !(info.GetDamageType() & DMG_NEVERGIB) || !m_fIsHeadless && info.GetDamageType() & DMG_SNIPER && !(info.GetDamageType() & DMG_NEVERGIB)) { DispatchParticleEffect("headshotspray_zombie", PATTACH_POINT_FOLLOW, this, "headcrab1", true); CGib::SpawnSpecificGibs(this, 3, 750, 1500, "models/gibs/agib_p3.mdl", 6); CGib::SpawnSpecificGibs(this, 3, 750, 1500, "models/gibs/agib_p4.mdl", 6); EmitSound("Gore.Headshot"); RemoveHead(); } else { return 2.0f; } } else { if (info.GetDamageType() & DMG_BUCKSHOT) { float flDist = FLT_MAX; if (info.GetAttacker()) { flDist = (GetAbsOrigin() - info.GetAttacker()->GetAbsOrigin()).Length(); } if (flDist <= POISONZOMBIE_BUCKSHOT_TRIPLE_DAMAGE_DIST) { return 3.0f; } } else { return 2.0f; } } } } return BaseClass::GetHitgroupDamageMultiplier(iHitGroup, info); }
void StrComparator::QueryInfo(char* qString, int qStrLen) { qString = RemoveHead(qString); int i; for(i = 0; i < 26; i++) qLetterCounter[i] = 0; for(i = 0; i < qStrLen; i++){ int pos = qString[i] - 'a'; if(pos >= 0 && pos < 26) qLetterCounter[pos]++; } }
/** * removes the tail node from the list, * or does nothing if the list is empty */ void SLList::RemoveTail() { if (head_ != NULL) { if (head_ == tail_) { RemoveHead(); } else { SLNode* temp = head_; while (temp->next_node() != tail_) temp = temp->next_node(); temp->set_next_node(NULL); delete tail_; tail_ = temp; size_ -= 1; } } }
void SLList::RemoveTail() { if(head_ == NULL) { //DO NOTHING } else if (head_->next_node() == NULL) { RemoveHead(); } else { SLNode* i = head_; SLNode* j = NULL; while (i->next_node() != NULL) { j = i; i = i->next_node(); } delete i; j->set_next_node(NULL); size_--; } }
///////////////////////////////////////////////////////////////////////////// // CUndLst ///////////////////////////////////////////////////////////////////////////// WORD CUndLst::SetUndMax (WORD usUndMax) { m_usUndMax = min (usUndMax, (WORD) pow (UNDEXTBAS, UNDEXTLEN)); ///////////////////////////////////////////////////////////////////////// // Set current position to NULL if undo has been inhibited ///////////////////////////////////////////////////////////////////////// if (!m_usUndMax) m_vpUndPos = NULL; ///////////////////////////////////////////////////////////////////////// // Remove oldest undo information // Note: Redo may still exceed max count, is adjusted on next create ///////////////////////////////////////////////////////////////////////// while (((WORD) m_olUndLst.GetCount() > m_usUndMax) && (m_vpUndPos != m_olUndLst.GetHeadPosition())) RemoveHead(); ///////////////////////////////////////////////////////////////////////// return (m_usUndMax); }
void SLList::RemoveTail() { if (head_ != NULL) //checks if the list is null { if(head_ -> next_node() == NULL) //checks if head is the only node { RemoveHead(); } else { SLNode *temp = NULL; //creates temp node and makes it equal to NULL SLNode *iterator = head_; //creates an iterator and makes it equal to head_ while((iterator -> next_node()) != NULL) //makes sure iterator stops at tail_ { temp = iterator; //temp is set to iterator before it moves on to the next node iterator = iterator -> next_node(); //iterator moves on and points to the next node in the list } //iterator should now point at tail_ and temp points to the node before the tail_ node temp -> set_next_node(NULL); //temp is set to point at NULL tail_ = temp; //tail_ points at temp node delete iterator; //iterator node is deleted iterator = NULL; //iterator points at null size_--; //the size of the list decreases } } }
bool SLList::RemoveFirstOccurence(int contents) { SLNode* node = new SLNode(contents); if (contents == GetHead()) { RemoveHead(); return true; } else if(contents == GetTail()) { RemoveTail(); return true; } else if(head_ == NULL) { return false; } else if (node == NULL) { return false; } else if (contents != GetHead() && contents != GetTail()) { SLNode* i = head_; SLNode* j = NULL; while (i->contents() != contents && i->next_node() != NULL) { j = i; i = i->next_node(); } if(i->next_node() == NULL && i->contents() != contents) { return false; } else { SLNode* temp = i->next_node(); SLNode* temp2 = i; delete temp2; j->set_next_node(temp); size_--; return true; } } else return false; }
int CCircleBuffer::Get(unsigned char * pBuffer, int nBytes) { int nTotalGetBytes = 0; if (pBuffer != NULL && nBytes > 0) { int nHeadBytes = min(m_nEndCap - m_nHead, nBytes); int nFrontBytes = nBytes - nHeadBytes; memcpy(&pBuffer[0], &m_pBuffer[m_nHead], nHeadBytes); nTotalGetBytes = nHeadBytes; if (nFrontBytes > 0) { memcpy(&pBuffer[nHeadBytes], &m_pBuffer[0], nFrontBytes); nTotalGetBytes += nFrontBytes; } RemoveHead(nBytes); } return nTotalGetBytes; }
float StrComparator::Dist(char* qString, char* tString, float threshold) { distCompTime++; qString = RemoveHead(qString); tString = RemoveHead(tString); int qStrLen = strlen(qString); int tStrLen = strlen(tString); int lenDiff = (qStrLen-tStrLen)>0?(qStrLen-tStrLen):(tStrLen-qStrLen); if(lenDiff > threshold) return lenDiff; int i,j; ////////////////////////////////////////////////////////// // letter counting optimization starts here ////////////////////////////////////////////////////////// for(i = 0; i < 26; i++) //tLetterCounter[i] = 0; tLetterCounter[i] = qLetterCounter[i] = 0; for(i = 0; i < tStrLen; i++){ int pos = tString[i] - 'a'; if(pos >= 0 && pos < 26) tLetterCounter[pos]++; } for(i = 0; i < qStrLen; i++){ int pos = qString[i] - 'a'; if(pos >= 0 && pos < 26) qLetterCounter[pos]++; } int exc_sum = 0; int bel_sum = 0; for(i = 0; i < 26; i++) { if(qLetterCounter[i] > tLetterCounter[i]) { exc_sum += qLetterCounter[i] - tLetterCounter[i]; if(exc_sum > threshold) return exc_sum; } else{ bel_sum += tLetterCounter[i] - qLetterCounter[i]; if(bel_sum > threshold) return bel_sum; } } /////////////////////////////////////////////////////// // letter counting optimization ends here /////////////////////////////////////////////////////// int min; for(i = 0; i < tStrLen + 1; i++) { if(i == 0) { for(j = 0; j < qStrLen + 1; j++) { matrix[i][j] = j; #ifdef _DEBUG_ cout << matrix[i][j] << " "; #endif } #ifdef _DEBUG_ cout << endl; #endif continue; } matrix[i][0] = i; min = qStrLen; #ifdef _DEBUG_ cout << matrix[i][0] << " "; #endif int startPos = (i - ((int)threshold + 1)) > 1 ? (i - ((int)threshold+1)) : 1; //int startPos = 1; int endPos = (i + ((int)threshold + 1)) < qStrLen ? (i + ((int)threshold + 1)) : qStrLen; //int endPos = qStrLen; if(startPos > 1) { matrix[i][startPos-1] = matrix[i-1][startPos - 1] < matrix[i-1][startPos-2] ? (matrix[i-1][startPos-1] + 1) : (matrix[i-1][startPos-2] + 1); } for(j = startPos; j <= endPos; j++) { if(tString[i - 1] == qString[j - 1]) matrix[i][j] = matrix[i - 1][j - 1]; else matrix[i][j] = matrix[i - 1][j - 1] + 1; if( (matrix[i][j - 1] + 1) < matrix[i][j]) matrix[i][j] = matrix[i][j - 1] + 1; if( (matrix[i - 1][j] + 1) < matrix[i][j]) matrix[i][j] = matrix[i - 1][j] + 1; #ifdef _DEBUG_ cout << matrix[i][j] << " "; #endif if(matrix[i][j] < min) min = matrix[i][j]; } if(j <= qStrLen) { matrix[i][j] = matrix[i][j - 1] < matrix[i - 1][j - 1] ? (matrix[i][j - 1] + 1) : (matrix[i - 1][j - 1] + 1); } if(min > threshold) return min; #ifdef _DEBUG_ cout << endl; #endif } return matrix[tStrLen][qStrLen]; }
//--------------------------------------------------------------------------- //--------------------------------------------------------------------------- void CTDPartitions::cleanup() { while (!IsEmpty()) delete RemoveHead(); }