Home > Back-end >  C + + beginners for help!
C + + beginners for help!

Time:09-27

I want to write a list class, in a list embedded in the generic class a node class members (with a generic) as a data storage unit,
Then write two return a pointer to the node function, appear problem,
Writing find_pre found that if the declaration is written on the outside, the compiler complains, write in it (find) will not,, why? If you must write the declaration on the outside, how should do?

 # include & lt; Cstdio> 
# include & lt; iostream>
# include & lt; Queue>
# include & lt; Vector>
# include & lt; Cstdlib>
# include & lt; Algorithm>

using namespace std;



The template & lt; The class T>
The class List {
Private:


Public:
The class Node {
T val.
Node * next;
};
Node * head;
Node * back;

The List () {head=new Node; The back=head; The head - & gt; Next=NULL; }

Bool utilities like is_empty that () {return head==back; }
Bool is_back (Node * p) {return p==back; }

Node * Find_pre va (T);
Node * Find va (T) {
The Node * p=Find_pre (va);
If (is_back (p)) {
return NULL;
}
The return p - & gt; next;
}

Bool F_Insert va (T);
Bool B_Insert va (T);

Bool Delete va (T);

Void the sort ();

To the List () {
Node * p=head, q;
While (p - & gt; Next) {
Q=p - & gt; next;
The delete p;
P=q;
}
The delete p;
}


};

The template & lt; The class T>
Node * List : : Find_pre (va) T {
The Node * p=head - & gt; Next, q=head;
If (utilities like is_empty that ()) {
return NULL;
}
While (p) {
If (p - & gt; Val==va) {
break;
}

Q=q - & gt; next;
P=p - & gt; next;
}
The return of q;

}
  • Related