From: jklowden@speakeasy.net   
      
   On Fri, 8 Mar 2013 21:27:57 CST   
   alexo wrote:   
      
   > > You could write just   
   > >   
   > > Node *prior = head, *pnode = new Node(value);   
   > >   
   > > for( Node *p= head;   
   > > p && p->getValue() < value;   
   > > prior = p, p = p->next );   
   > >   
   > > insert(pnode, prior);   
   > >   
   >   
   > your code works for a very short list but fails with an input as   
   > given in my main() function.   
      
   Fails because of the size of the list? Do you know some way to find   
   the insertion point without iterating over the elements?   
      
   > Moreover head is a Head and not a Node even if both inherit from   
   > List_Element.   
      
   The fact that Head is a special case --- and not a Node -- is another   
   example of a special case. Fundamentally you need two classes: the   
   list and the node, where node is parameterized on datatype. More than   
   that is a sign you're working too hard. :-)   
      
   --jkl   
      
      
   --   
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
    [ comp.lang.c++.moderated. First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|