i want to know whats the error over here. i just want to store the three value in a node and making a linked list but after storing two nodes that is headptr and than temptr, when the third node is made it stops.
I think my error is somewhere in "while loop" bt i couldnt find it.
node* addnode(int x, int r,int c)// x = value,r = row, c = coloumn
{
node* nodeptr = new node;
node* temptr;
temptr = headptr;
nodeptr->val = x;;
nodeptr->rowval = r;
nodeptr->colval = c;
nodeptr->next = NULL;
cout<<"nodeprtr->value"<<nodeptr->val<<endl;
cout<<"nodeptr->row"<<nodeptr->rowval<<endl;
cout<<"nodeptr->col"<<nodeptr->colval<<endl;
if ( headptr == NULL )
{
headptr = nodeptr;
cout<<"headptr->value"<<" "<<headptr->val<<endl;
cout<<"headptr->row"<<" "<<headptr->rowval<<endl;
cout<<"headptr->col"<<" "<<headptr->colval<<endl;
return headptr;
}
else
{
if (headptr != NULL )
{
while(temptr->next!= NULL )
{
temptr->next = temptr;
}
}
temptr->next = nodeptr;
temptr = nodeptr;
cout<<"temptr->val"<<" "<<temptr->val<<endl;
cout<<"temptr->rowval"<<" "<<temptr->rowval<<endl;
cout<<"temptr->colval"<<" "<<temptr->colval<<endl;
return nodeptr;
}
}