c++ - Linked list insertion -


the emissonlist object list of shows info. problem in insert function.

class emissionlist { private: emission *head=null; public: void insert(emission *anode); emission *gethead() {     return head; }; void puthead(emission *newhead) {     head=newhead;     head->next = null; } void printemissions(); };   void emissionlist::insert(emission *anode) { emission *ptr=gethead(); if (head == null){     puthead(anode); }else{     while(ptr!= null){         ptr = ptr->next;     }     ptr = anode;     ptr->next=null; }} 

i trying add list encounter problems.

first of design of class emissionlist bad.

nevertheless function can defined following way

void emissionlist::insert( emission *anode )  {     emission *current = gethead();      if ( current == null )     {         puthead( anode );     }     else     {        while ( current->next ) current = current->next;        anode->next = current->next;        current->next = anode;     } } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -