本文整理汇总了C++中ItemType::ComparedTo方法的典型用法代码示例。如果您正苦于以下问题:C++ ItemType::ComparedTo方法的具体用法?C++ ItemType::ComparedTo怎么用?C++ ItemType::ComparedTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ItemType
的用法示例。
在下文中一共展示了ItemType::ComparedTo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RetreiveItem
void SortedType::RetreiveItem(ItemType& item, bool& found)
{
int midPoint, first = 0, last = length - 1;
bool moreToSearch = (first <= last);
found = false;
while(moreToSearch && !found)
{
midPoint = (first + last) / 2;
switch(item.ComparedTo(info[midPoint]))
{
case LESS:
last = midPoint - 1;
moreToSearch = (first <= last);
break;
case GREATER:
first = midPoint + 1;
moreToSearch = (first <= last);
break;
case EQUAL:
found = true;
item = info[midPoint];
break;
}
}
}
示例2: InsertItem
void SortedType::InsertItem(ItemType item)
{
int location = 0;
bool moreToSearch = (location < length);
while(moreToSearch)
{
switch(item.ComparedTo(info[location]))
{
case LESS:
moreToSearch = false;
break;
case GREATER:
location++;
moreToSearch = (location < length);
break;
}
}
for(int index = length; index > location; index--)
{
info[index] = info[index - 1];
}
info[location] = item;
length++;
}
示例3: GetItem
ItemType SortedType::GetItem(ItemType item, bool& found)
{
bool moreToSearch;
NodeType* location;
location = listData;
found = false;
moreToSearch = (location != NULL);
while (moreToSearch && !found)
{
switch (item.ComparedTo(location->info))
{
case LESS : moreToSearch = false;
break;
case GREATER : location = location->next;
moreToSearch = (location != NULL);
break;
case EQUAL : found = true;
item = location->info;
break;
}
}
return item;
}
示例4: DeleteItem
void SortedType::DeleteItem(ItemType item)
{
NodeType* location = listData;
NodeType* tempLocation;
if(item.ComparedTo(listData->info) == EQUAL)
{
tempLocation = location;
listData = listData->next;
}
else
{
while(item.ComparedTo((location->next)->info) != EQUAL)
{
location = location->next;
}
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
length--;
}
示例5: DeleteItem
void SortedType::DeleteItem(ItemType item)
{
int location = 0;
while(item.ComparedTo(info[location]) != EQUAL)
{
location++;
}
for(int index = location + 1; index< length; index++)
{
info[index - 1] = info[index];
}
length--;
}
示例6: PutItem
void SortedType::PutItem(ItemType item)
{
NodeType* newNode;
NodeType* predLoc;
NodeType* location;
bool moreToSearch;
location = listData;
predLoc = NULL;
moreToSearch = (location != NULL);
while(moreToSearch)
{
switch(item.ComparedTo(location->info))
{
case GREATER : predLoc = location;
location = location->next;
moreToSearch = (location != NULL);
//std::cout << "We are in greater\n";
break;
case EQUAL : predLoc = location;
location = location->next;
moreToSearch = false;
break;
case LESS : moreToSearch = false;
break;
}
}
newNode = new NodeType;
newNode->info = item;
if(predLoc == NULL)
{
newNode->next = listData;
listData = newNode;
}
else
{
newNode->next = location;
predLoc->next = newNode;
}
length++;
}