Class for link list

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:
1
2
3
4
5
6
7
8
9
10
11
12
13
node *temp
temp = new node;
temp->data=10;
temp->next=NULL;

if(start_point == NULL) start_point=temp;
else{
node *temp2=start_point;
while(temp2->next != NULL){
temp2 = temp2->next;
}
temp2->next = temp;
}



Through my research, i found out a code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#
class linklist
#
{
#
     private:
#
 
#
             struct node
#
         {
#
              int data;
#
            node *link;
#
         }*p;
#
 
#
   public:
#
 
#
             linklist();
#
         void append( int num );
#
         void add_as_first( int num );
#
         void addafter( int c, int num );
#
         void del( int num );
#
         void display();
#
         int count();
#
         ~linklist();
#
};

why this fellow needs to add a struct inside the class?

Thx for reading =P
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...
Topic archived. No new replies allowed.