<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                # 13.4 wxList和wxNode wxList類是一個雙向鏈表,可以用來存儲任何類型的數據.wxWidgets需要你顯式的定義一個針對某種數據類型的新的類來使用它,以便對存儲于其中的數據提供足夠的類型檢查.wxList類還允許你指定一個索引類型以便進行基本的查找操作(如果你想使用基于結構的快速隨機訪問,請參考下一節的 wxHashMap類). wxList使用了一個虛類wxNode.當你定義一個新的wxList派生類的時候,你同時定義了一個派生自wxNodeBase的類,以便對節點提供類型安全檢查.節點類最重要的函數包括:GetNext,GetPrevious和GetData.它們的功能顯而易見,分別為:獲取下一個子項,獲取前一個子項以及獲取子項的數據. 唯一值得說明的是wxList的刪除操作,默認情況下,從鏈表中移除一個節點并不會導致節點內部數據的釋放.你需要調用 DeleteContents函數來改變這種默認的行為,設置數據隨著節點一起釋放.如果你想清除整個鏈表并且釋放其中的數據,你應該先調用 DeleteContents,參數為True,然后再調用Clear函數. 我們用不著在這里把手冊的內容重新粘貼一遍.我們將舉一個簡單的例子來演示怎樣創建你自己的鏈表類型.注意WX_DECLARE_LIST宏通常應該位于頭文件中,而WX_DEFINE_LIST宏通常應該位于源文件中. ``` // 我們將存儲于鏈表的數據類型 class Customer { public: int CustID; wxString CustName; }; // 通常應該位于頭文件中 WX_DECLARE_LIST(Customer, CustomerList); // 下面的定義應該位于源文件中,并且通常位于所有Customer聲明之后 #include &lt;wx/listimpl.cpp&gt; WX_DEFINE_LIST(CustomerList); // 用于排序的比較函數 int listcompare(const Customer** arg1, const Customer** arg2) { return ((*arg1)->CustID &lt; (*arg2)->CustID); } // 鏈表操作舉例 void ListTest() { // 定義一個我們自定義鏈表的實例 CustomerList* MyList = new CustomerList(); bool IsEmpty = MyList->IsEmpty(); // will be true // 創建一些自定義對象實例 Customer* CustA = new Customer; CustA->CustID = 10; CustA->CustName = wxT("Bob"); Customer* CustB = new Customer; CustB->CustID = 20; CustB->CustName = wxT("Sally"); Customer* CustC = new Customer; CustC->CustID = 5; CustC->CustName = wxT("Dmitri"); // 將其增加到鏈表中 MyList->Append(CustA); MyList->Append(CustB); // 實現隨機插入 MyList->Insert((size_t)0, CustC); int Count = MyList->GetCount(); // will be 3 // 如果找不到,返回wxNOT_FOUND int index = MyList->IndexOf(CustB); // will be 2 // 自定義的節點里包含了我們自定義的類型 CustomerList::Node* node = MyList->GetFirst(); // 節點遍歷 while (node) { Customer* Cust = node->GetData(); // 進行一些處理 node = node->GetNext(); } // 返回特定位置的節點 node = MyList->Item(0); // 按照排序函數排序 MyList->Sort(listcompare); // 移除包含某個對象的節點 MyList->DeleteObject(CustA); // 我們需要自己釋放這個對象 delete CustA; // 找到包含某個對象的節點 node = MyList->Find(CustB); // 指示內部數據隨節點的刪除而刪除 MyList->DeleteContents(true); // 刪除B的節點的時候,B也被釋放了 MyList->DeleteNode(node); // 現在調用Clear,所有的節點和其中數據都將被釋放 MyList->Clear(); delete MyList; } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看