e06-02.cpp
来自「游戏开发数据结构Data Structures for Game Program」· C++ 代码 · 共 37 行
CPP
37 行
// =======================================================
// Chapter 6, Example 2
// Iterating through a simple list.
// =======================================================
#include "SLinkedList.h"
#include <iostream.h>
void main()
{
// create a new linked list.
SListNode<int>* list = new SListNode<int>;
list->m_data = 10;
// insert 30, then 20 before that, so the list is 10, 20, 30.
list->InsertAfter( 30 );
list->InsertAfter( 20 );
cout << "the list contains: ";
// create a new iterator, and make it point to the
// beginning of the list.
SListNode<int>* itr = list;
cout << itr->m_data << ", ";
// move the iterator to the next node in the list.
itr = itr->m_next;
cout << itr->m_data << ", ";
// move the iterator forward again.
itr = itr->m_next;
cout << itr->m_data << ", ";
// reset the iterator to the beginning again.
itr = list;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?