本文整理汇总了C++中LList::comparisonFunction方法的典型用法代码示例。如果您正苦于以下问题:C++ LList::comparisonFunction方法的具体用法?C++ LList::comparisonFunction怎么用?C++ LList::comparisonFunction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LList
的用法示例。
在下文中一共展示了LList::comparisonFunction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testRemoval
void testRemoval() {
LList *list = newList( comparisonFunction );
const int numElements = 1000;
// Insert elements
for( int i = 0; i < numElements; i++ ) {
listInsert( list, mallocInt(i) );
}
// Remove the elements and ensure that the right elements were removed
for( int i = 0; i < numElements; i++ ) {
int *elementToRemove = mallocInt(i);
int *removedElement = listRemove( list, elementToRemove );
assertNotNull( removedElement, "removedElement is null!\n" );
int comparisonResult = list->comparisonFunction( elementToRemove, removedElement );
assertTrue( comparisonResult == 0, "compare(%d, %d) != 0\n", *elementToRemove,
*removedElement );
free( elementToRemove );
free( removedElement );
}
// Free the list
listFree( list );
}
示例2: testListFind
void testListFind() {
LList *list = newList( comparisonFunction );
const int numElements = 1000;
// Insert the elements
for( int i = 0; i < numElements; i++ ) {
listInsert( list, mallocInt(i) );
}
// Find the elements
for( int i = 0; i < numElements; i++ ) {
int *intToFind = mallocInt(i);
// Ensure that the find didn't return null
ListNode *findResult = listFind( list, intToFind );
assertNotNull( findResult, "find(i) should not be NULL!\n" );
// Ensure that the elements are equal
int comparisonResult = list->comparisonFunction( intToFind, findResult->data );
assertTrue( comparisonResult == 0, "find(%d)->data != %d\n", i, i );
free( intToFind );
}
// Free the list
listFree( list );
}