c++ - Deleting linked objects -


I have two squares: "node" and "poly" node objects connected together to create a linked list I keep the poly object a pointer on the first node. I am trying to eliminate memory for the entire "poly". I want to remove the poly - then call the function within the poly-disaster (like "freepoly") which I have given to the complete list of node object Will help again - Removing all the nodes.

Class definition:

  class node {private: double coeff; Intel exponent; Node * next; Public: node (double c, int e, node * nodobject) {coeff = c; Exponent = e; Next = nodeobjectPtr; } ~ Node () {printf ("node destroyed"); // ??? } Class policy {Private: node * Start; Public: Poly (node ​​* head) / * Constructor function * / {start = head; } ~ Poly () / * district * / / // ??? } Free of charge (); }; Zero poly :: free poly () {// ??? }   

I have tried a lot of things, but essentially I get stuck where I am only removing the first node object. I have lost the indicator for other nodes. ... and leakage of memory because I can not reach them anymore for their extinction.

Instead of a do-it-it-linked-linked list, a std :: vector can make many problems and work. Until it is not for learning.

He said, do it

  ~ poly () / * destructor * / {while (start! = 0) {node * p_doomed = start; Start = start-> next; Delete p_doomed; }}   

There are several other ways to do this, but there is a pattern above that explains to you how to do this.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -