class - C++ Classes - What is wrong with my program? -


insert method appends item end of linked list.

can't figure out how code case node null, , want add it.

struct node{        int data;        node *next;         node(int data):data(data),next(null){}         void insert(int data){             if (this==null){                this=new node(data); // compiler complaining here.                                     // how go setting value of (which presently null) new node?             }        } } 

you can not assign value this pointer special keyword , should point valid block of memory. looking @ usage, trying mean this:

void insert(int data){             if (!next){                next = new node(data);              } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -