|
From: <or...@vp...> - 2002-11-19 20:32:53
|
Hello j b!
Jörgen wrote:
> Make sure to test that
> s->firstptr != NULL
> otherwise the right-hand-side of the statement
> s->firstptr=s->firstptr->next;
> would be
> NULL->next
> and that is ofcourse wrong
Oh, yes, I forgot that, of course you need to check whether it is
NULL, or not, sorry %) But despite that, I still recommend to use the
C++ built-in (standard library) lists. Or if you don't know how to use
them, then try this code for pop:
node *pop(stack *s){
node *nptr; /* Only a pointer */
nptr = s->firstptr;
if (s->firstptr != NULL) s->firstptr = s->firstptr->next;
return nptr;
}
pop() will return NULL, if there are no elements. And you should
delete the node from "outside", when you "popped" it out and done all
calculations with it, so that you won't trash the memory.
--
Best regards,
Oroszi Balázs mailto:or...@vp...
P.S.: Correct the code, if it is wrong, please!
PGP-FP: FB80 8A43 2664 6126 E465 46E2 2546 CFA3 C25B 9F70
finger -l or...@se...
|