我想寫一個鏈表類。在一個list泛型類里內嵌了一個node類(有一個泛型成員)作為存盤的資料單元。
然后在寫兩個回傳node指標的函式的時候,就出現問題了。
寫find_pre的時候發現,如果將declaration寫在外面,編譯器會報錯。寫在里面(見find)就不會。求解,為什么?如果一定要把declaration寫在外面,應該怎么做?

#include <cstdio>
#include <iostream>
#include <queue>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
template <class T>
class List{
private:
public:
class Node{
T val;
Node * next;
};
Node * head;
Node * back;
List(){head = new Node;back=head;head->next=NULL;}
bool is_empty(){return head==back;}
bool is_back(Node * p){return p==back;}
Node * Find_pre(T va);
Node * Find(T va){
Node * p =Find_pre(va);
if (is_back(p)) {
return NULL;
}
return p->next;
}
bool F_Insert(T va);
bool B_Insert(T va);
bool Delete(T va);
void sort();
~List(){
Node * p = head,q;
while (p->next) {
q = p->next;
delete p;
p = q;
}
delete p;
}
};
template <class T>
Node * List<T>:: Find_pre(T va){
Node * p = head->next,q=head;
if (is_empty()) {
return NULL;
}
while (p) {
if (p->val == va) {
break;
}
q = q->next;
p = p->next;
}
return q;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/84673.html
標籤:基礎類
上一篇:MFC 網上PictureEx類播放gif影片,但是在win 7 電腦個性化設定視窗蘋果綠后,播放gif時,播放時會出現干擾現象,求大神回復一下,怎么解決?
