当前位置: 首页>>代码示例>>C++>>正文


C++ ItemType::ComparedTo方法代码示例

本文整理汇总了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;
        }
    }
}
开发者ID:ShawonAshraf,项目名称:CSE225CodesNSU,代码行数:26,代码来源:SortedType.cpp

示例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++;
}
开发者ID:ShawonAshraf,项目名称:CSE225CodesNSU,代码行数:27,代码来源:SortedType.cpp

示例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;
}
开发者ID:Just-Sieb,项目名称:School,代码行数:27,代码来源:sorted.cpp

示例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--;
}
开发者ID:Just-Sieb,项目名称:School,代码行数:21,代码来源:sorted.cpp

示例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--;
}
开发者ID:ShawonAshraf,项目名称:CSE225CodesNSU,代码行数:15,代码来源:SortedType.cpp

示例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++;
}
开发者ID:Just-Sieb,项目名称:School,代码行数:47,代码来源:sorted.cpp


注:本文中的ItemType::ComparedTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。