Hi,

I'm an amateur C/C++ programmer from Argentina.  I'm a
new member of this group.

I'm reading "Data Structures and Program Design in
C++" by R. Kruse and A. Ryba.  On page 129 the
following code for the push method of a linked stack
is presented:

Error_code Stack::push(const Stack_entry &item)
{
  Node *new_top = new Node(item, top_node);
  if(new_top == NULL) return overflow;
  top_node = new_top;
  return success;
}

My question: isn't this line:

  delete new_top;

needed after the assignment "top_node = new_top;"? 
Without this extra line, wouldn't garbage mount up
when the function ends and new_top runs out of scope?

Nothing is mentioned about this, neither in the book
not in the errata.  How would you check if you're
accidentally accumulating garbage?

All your comments will be much appreciated.

Ignacio
Buenos Aires, Argentina





      Lesen Sie Ihre E-Mails auf dem Handy.
www.yahoo.de/go

Reply via email to