1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

doubly linked list

Discussion in 'C' started by musicmancanora4, May 7, 2007.

Thread Status:
Not open for further replies.
  1. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys sorry for the long extensive code but i am having some trouble with a delete function. It seems that when i delete a node in the middle its loosing the tail so its loosing the nodes which are underneath it.

    Im positive that it has nothing to do with my Delete funtion however i am very suspicious that i may not be loading the linked list properly in this function which is causing it. I cant find anything wrong when its inserting in between the list but i just want to make sure? Its suppose to work as a doubly linked list implementation





    Code:
           current = menu->headCategory;
    
        /* Find the right category for the item to be inserted */
        while(current != NULL)
        {
             /* If the right category has been found for the item to be
             inserted. */
             if(strcmp(current->categoryID,categoryIDcopy) == 0)
        {
        
        submenuCurrent = current->headItem;
    
       /* Increase the number of items when an item is added */
       
        current->numItems++;
    
       /* If nothing exists in the category, add to the head of the
       item list. */
    
       if(submenuCurrent == NULL)
       {
             submenuCurrent = submenuNode;
             current->headItem = submenuCurrent;
             submenuCurrent->nextItem = NULL;
             submenuCurrent->prevItem = NULL;
       }
       else
       {
             submenuPrevious = NULL;
             /* Find the right position to insert the item. */
             
            while((submenuCurrent != NULL) &&
            strcmp(submenuCurrent->itemName,
            submenuNode->itemName) < 0)
      {
            submenuPrevious = submenuCurrent;
            submenuCurrent->prevItem = submenuPrevious;
            submenuCurrent = submenuCurrent->nextItem;
      }
            /* If inserting at the head of the list. */
            if(submenuCurrent == current->headItem)
           {
               submenuNode->nextItem = submenuCurrent;
               submenuCurrent = submenuNode;
               current->headItem = submenuCurrent;
               submenuNode->prevItem = NULL;
           }
            /* If adding to the end of the list. */
           else if(submenuCurrent == NULL)
          {
               submenuPrevious->nextItem = submenuNode;
               submenuCurrent = submenuNode;
               submenuCurrent->nextItem = NULL;
               submenuNode->prevItem = submenuPrevious;
          }
            /* If adding somewhere in between the list. */
          else
          {
               submenuPrevious->nextItem = submenuNode;
               submenuNode->nextItem = submenuCurrent;
               submenuNode->prevItem = submenuPrevious;
               submenuCurrent->prevItem = submenuNode;
    
          }
      }
    }
              current = current->nextCategory;
      
    
    
    
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,285
    Likes Received:
    364
    Trophy Points:
    83
    Duplicate of [thread=4173]doubly linked list trouble[/thread]. Thread closed. Please dont have the same thread over and over again as that will dilute the need of yours to get any response.
     
Thread Status:
Not open for further replies.

Share This Page