本文整理汇总了C++中SortedListPtr::destruct方法的典型用法代码示例。如果您正苦于以下问题:C++ SortedListPtr::destruct方法的具体用法?C++ SortedListPtr::destruct怎么用?C++ SortedListPtr::destruct使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedListPtr
的用法示例。
在下文中一共展示了SortedListPtr::destruct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SLRemove
int SLRemove(SortedListPtr list, void *newObj)
{
SortedNodePtr current = list->head, previous = NULL;
while(current->link != NULL && list->compare(current->value, newObj) != 0)
{
// Store current node into previous
previous = current;
// Move to next node
current = current->link;
}
// Only remove if count on node is one or lower
if(previous == NULL && current->count <= 1)
{
list->head = current->link;
list->destruct(current->value);
free(current);
// Decrement list size
list->counter--;
return 1;
}
else if(current->count <= 1)
{
// Previous points to node after the one being deleted
previous->link = current->link;
// Free the memory
list->destruct(current->value);
free(current);
// Decrement list size
list->counter--;
return 1;
}
else
{
// Make reference count go down by one
current->count--;
}
// Couldn't remove
return 0;
}
示例2: SLDestroy
void SLDestroy(SortedListPtr list)
{
// Traverse to end up list while deallocating memory
while(list->head != NULL)
{
// TempNode points to current and current points to next node
SortedNodePtr tempNode = list->head;
list->head = tempNode->link;
// Free data if need be
list->destruct(tempNode->value);
// Free the node
free(tempNode);
}
// Free everything else in list
free(list->head);
free(list);
}