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


C++ sequence::advance方法代码示例

本文整理汇总了C++中sequence::advance方法的典型用法代码示例。如果您正苦于以下问题:C++ sequence::advance方法的具体用法?C++ sequence::advance怎么用?C++ sequence::advance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sequence的用法示例。


在下文中一共展示了sequence::advance方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_items

// **************************************************************************
// bool test_items(sequence& test, size_t s, size_t i, double items[])
//   The function determines if the test sequence has the correct items
//   Precondition: The size of the items array is at least s.
//   Postcondition: A return value of true indicates that test.current()
//   is equal to items[i], and after test.advance() the result of
//   test.current() is items[i+1], and so on through items[s-1].
//   At this point, one more advance takes the cursor off the sequence.
//   If any of this fails, the return value is false.
//   NOTE: The test sequence has been changed by advancing its cursor.
// **************************************************************************
bool test_items(sequence& test, size_t s, size_t i, double items[])
{
    bool answer = true;
    
    cout << "The cursor should be at item [" << i << "]" << " of the sequence\n";
    cout << "(counting the first item as [0]). I will advance the cursor\n";
    cout << "to the end of the sequence, checking that each item is correct...";
    cout.flush( );
    while ((i < s) && test.is_item( ) && (test.current( ) == items[i]))
    {
        i++;
        test.advance( );
    }

    if ((i != s) && !test.is_item( ))
    {   // The test.is_item( ) function returns false too soon.
        cout << "\n    Cursor fell off the sequence too soon." << endl;
        answer = false;
    }
    else if (i != s)
    {   // The test.current( ) function returned a wrong value.
        cout << "\n    The item [" << i << "] should be " << items[i] << ",\n";
        cout << "    but it was " << test.current( ) << " instead.\n";
        answer = false;
    }
    else if (test.is_item( ))
    {   // The test.is_item( ) function returns true after moving off the sequence.
        cout << "\n    The cursor was moved off the sequence,";
        cout << " but is_item still returns true." << endl;
        answer = false;
    }

    cout << (answer ? "Passed." : "Failed.") << endl;
    return answer;
}
开发者ID:dorazhuyi,项目名称:hws,代码行数:46,代码来源:seq_ex2.cpp

示例2: show_list

void show_list(sequence<T> src)
// Pre: (none)
// Post: The items of src are printed to cout (one per line).
{
   for ( src.start(); src.is_item(); src.advance() )
      cout << src.current() << "  ";
}
开发者ID:brownbagspecial,项目名称:School-Work,代码行数:7,代码来源:sequenceTest.cpp

示例3: show_sequence

void show_sequence(sequence src)
{
    for ( src.start(); src.is_item(); src.advance() )
        cout << src.current() << endl;
}
开发者ID:bengut10,项目名称:dataStructures2,代码行数:5,代码来源:Assign03.cpp

示例4: show_list

void show_list(sequence<T> src)
{
   for ( src.start(); src.is_item(); src.advance() )
      cout << src.current() << "  ";
}
开发者ID:Saamy88,项目名称:Data-Structures,代码行数:5,代码来源:sequenceTest.cpp

示例5: show_sequence

void show_sequence(sequence display)
// Library facilities used: iostream
{
    for (display.start( ); display.is_item( ); display.advance( ))
        cout << display.current( ) << endl;
}
开发者ID:natethinks,项目名称:3.2assignment,代码行数:6,代码来源:driver.cpp


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