PREV INDEX NEXT

Author: Stan Eisenstat
Subject: Re: [Cs223] Pointer ? / IsEmptyD()
Date: Saturday, 14 Mar 2020, 14:28:40


    > Message Posted By: Unknown
    >
    > I see that in Aspnes' pop() function, he writes:
    >
    > e = s;
    > s = e->next;
    > free(e);
    >
    > where e is a temp pointer to the node. Why is it necessary to write s =
    > e->next, rather than s = s->next? Is there a difference?

Since s = e->next and s = s->next have the same effect,
either can be used.
=====

    > Also for isEmptyD() how is it possible for the value of *d to change
    > within the function? Aren't we just checking to see if the T stack and the
    > H stack are empty and returning true or false accordingly?

That depends on how isEmpty() is implemented.  For
example, suppose that isEmptyD() just calls headD() and
ignores the string pointer if the Deque is nonempty;
and that, as I posted earlier:

  If the H stack is empty and the T stack is not, then
  headD() must change the internal structure of *D.  Now
  imagine an implementation where *D is a pointer to a
  malloc()ed block of storage and such a change induces
  a change in the amount of storage required (e.g., it
  reclaims unused space).
   
--Stan-
PREV INDEX NEXT