Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   delete middle doubly linked list node (http://www.go4expert.com/forums/delete-middle-doubly-linked-list-node-t4197/)

musicmancanora4 7May2007 08:39

delete middle doubly linked list node
 
undefinedHey guys i have a seperate delete function and im sure the code is correct however it wont delete the middle node properly it seems its loosing the tail. I have a suspicion that its when its loading the doubly linked list into the middle is causing the problem. Could someone look at my load function and see whether im adding at the middle correctly?


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;


shabbir 7May2007 11:28

Re: delete middle doubly linked list node
 
Duplicate of doubly linked list trouble. Thread closed. If you continue to have the same thread over and over again your account will get banned. You already have this third duplicate thread and normally your account should have been banned but I thought of giving you one last warning before doing so.


All times are GMT +5.5. The time now is 09:06.