Thread: mkng linked list

  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    5

    Red face mkng linked list

    this code only makes two nodes and at the time of making third node it stucks
    Code:
    	void addnode(int x, int r,int c)//+++++++++++++++++++++++++++++=addnode
    	
    	{
    	
    		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;
    		}
    	}

  2. #2
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    733
    Where is any function call of addnode?
    And
    What is 'node'?
    What is x, r and c?
    What is headptr?
    How do you pass list object to the addnode function?
    I see commented return statements while the function is 'void'. What did you want to return?
    Last edited by kmdv; 11-06-2010 at 06:59 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ Linked list program need help !!!
    By dcoll025 in forum C++ Programming
    Replies: 1
    Last Post: 04-20-2009, 10:03 AM
  2. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  3. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM

Tags for this Thread