本文整理汇总了C++中SortedListPtr::compareTo方法的典型用法代码示例。如果您正苦于以下问题:C++ SortedListPtr::compareTo方法的具体用法?C++ SortedListPtr::compareTo怎么用?C++ SortedListPtr::compareTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedListPtr
的用法示例。
在下文中一共展示了SortedListPtr::compareTo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: StringInsert
int StringInsert(SortedListPtr list, void *newObj, char*key){
if(list->head==NULL)
{
NodePtr newNode = NodeCreate(newObj, key);
list->head = newNode;
return 1;
}
else
{
NodePtr cur = (NodePtr)malloc(sizeof(Node));
cur = list->head;
NodePtr prev = NULL;
/*Move the cur and prev pointers until cur points to the node where the newObj
should be inserted and prev points to the node before that point. */
CompareFuncT comp = list->compareTo;
int aa = strcmp(key, cur->name);
if(aa < 0)
{
NodePtr newNode = NodeCreate(newObj, key);
newNode->next = cur;
list->head = newNode;
newNode->refcount += 1;
return 1;
}
else
{
while((cur != NULL) && (list->compareTo(newObj,cur->data)) >= 0)
{
if(newObj == cur->data)
{
return 1;
}
prev = cur;
cur = cur->next;
}
NodePtr newNode = NodeCreate(newObj, key);
/*Insert*/
prev->next = newNode;
newNode->refcount += 1;
newNode->next = cur;
return 1;
}
}
}