hi all experts,
a newbie is back for question =)...
for me, to create a link list using class the code will be:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
class node{
public:
node();
void addnode();
void delnode();
private:
int data;
node *next;
}*start_point;
node::node(){
start_point = NULL;
}
something like this rite?
BUT!
when i running my code and add node, my start_point always be NULL although i have added some data before. izit my constructor problem or my code problem?
This is how my addnode code look like:
the structure that is declared is a total diff identity...it is representing a complete node...
and the class will contain the data inside it...it is has-a relationship...never tries what u have written in ur code...also there must be a HEAD variable inside class that should always point to the start of the list...
in ur code if u allocate the memory then each time a new object of the whole class shall be created...which is not the case for linked lists...each time the complete object of node(struct) must be created and the outer/main class contains the implementation...
if u do not want the struct then u can take a class also inside the class...
hope this solve ur doubt...