1. <i id='OnIhM'><tr id='OnIhM'><dt id='OnIhM'><q id='OnIhM'><span id='OnIhM'><b id='OnIhM'><form id='OnIhM'><ins id='OnIhM'></ins><ul id='OnIhM'></ul><sub id='OnIhM'></sub></form><legend id='OnIhM'></legend><bdo id='OnIhM'><pre id='OnIhM'><center id='OnIhM'></center></pre></bdo></b><th id='OnIhM'></th></span></q></dt></tr></i><div id='OnIhM'><tfoot id='OnIhM'></tfoot><dl id='OnIhM'><fieldset id='OnIhM'></fieldset></dl></div>
      <bdo id='OnIhM'></bdo><ul id='OnIhM'></ul>

  2. <small id='OnIhM'></small><noframes id='OnIhM'>

    <tfoot id='OnIhM'></tfoot>

    1. <legend id='OnIhM'><style id='OnIhM'><dir id='OnIhM'><q id='OnIhM'></q></dir></style></legend>

      单链打印 C++

      时间:2023-10-18
    2. <tfoot id='qWgl2'></tfoot>

        <legend id='qWgl2'><style id='qWgl2'><dir id='qWgl2'><q id='qWgl2'></q></dir></style></legend>
        <i id='qWgl2'><tr id='qWgl2'><dt id='qWgl2'><q id='qWgl2'><span id='qWgl2'><b id='qWgl2'><form id='qWgl2'><ins id='qWgl2'></ins><ul id='qWgl2'></ul><sub id='qWgl2'></sub></form><legend id='qWgl2'></legend><bdo id='qWgl2'><pre id='qWgl2'><center id='qWgl2'></center></pre></bdo></b><th id='qWgl2'></th></span></q></dt></tr></i><div id='qWgl2'><tfoot id='qWgl2'></tfoot><dl id='qWgl2'><fieldset id='qWgl2'></fieldset></dl></div>

        <small id='qWgl2'></small><noframes id='qWgl2'>

              <tbody id='qWgl2'></tbody>
              • <bdo id='qWgl2'></bdo><ul id='qWgl2'></ul>

              • 本文介绍了单链打印 C++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试以 {1,2,3,4,etc} 格式选择我的链.您可以在下面找到包含节点布局的头文件.我只是对如何循环遍历我的列表以打印出 Item 感到困惑.

                I am trying to pick my chain in the format {1,2,3,4,etc}. You can find the header file below which will have the layout of the nodes. I am just confused on how I should go about cycling through my list to print out Item.

                任何指导将不胜感激!

                set.h

                using namespace std;
                
                #include <iostream>
                
                class Set
                {
                  private:
                
                    struct Node
                    {
                      int Item;      // User data item
                      Node * Succ;   // Link to the node's successor
                    };
                
                    unsigned Num;    // Current count of items in the set
                    Node * Head;     // Link to the head of the chain
                
                  public:
                
                    // Return information about the set
                    //
                    bool is_empty() const { return Num == 0; }
                    unsigned size() const { return Num; }
                
                    // Initialize the set to empty
                    //
                    Set();
                
                    // Insert a specified item into the set, if possible
                    //
                    bool insert( int );
                
                    // Display the set
                    //
                    void display( ostream& ) const;
                
                };
                

                推荐答案

                假设你的列表是循环的,你可以这样使用:

                Suppose your list is cyclical, you can use this:

                struct Node *n = begin;
                
                if (n != NULL) {
                    //do something on it
                    ...
                    for (n = begin->Succ; n != begin; n = n->Succ) {
                    }
                }
                

                struct Node *n = begin;
                if (n != NULL) {        
                    do {        
                        //do something
                        ...
                        n = n->Succ;
                    } while (n != begin)
                }
                

                这篇关于单链打印 C++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:正确实现单链表 C++ 下一篇:为什么 std::list::reverse 具有 O(n) 复杂度?

                相关文章

                      <bdo id='Kasar'></bdo><ul id='Kasar'></ul>

                    <small id='Kasar'></small><noframes id='Kasar'>

                    <i id='Kasar'><tr id='Kasar'><dt id='Kasar'><q id='Kasar'><span id='Kasar'><b id='Kasar'><form id='Kasar'><ins id='Kasar'></ins><ul id='Kasar'></ul><sub id='Kasar'></sub></form><legend id='Kasar'></legend><bdo id='Kasar'><pre id='Kasar'><center id='Kasar'></center></pre></bdo></b><th id='Kasar'></th></span></q></dt></tr></i><div id='Kasar'><tfoot id='Kasar'></tfoot><dl id='Kasar'><fieldset id='Kasar'></fieldset></dl></div>
                  1. <legend id='Kasar'><style id='Kasar'><dir id='Kasar'><q id='Kasar'></q></dir></style></legend>
                    <tfoot id='Kasar'></tfoot>