Search This Blog

Data Structure programming

5 comments:

  1. what algorithm has to use for programme delete the second last node from the list.

    ReplyDelete
    Replies
    1. the best way to delete second last node in single traverse
      void delete_second_last_node(my_list_t *node)
      {
      my_list_t *temp = node;
      my_list_t *cur = NULL;
      while(temp->next->next != NULL)
      {
      cur = temp;
      temp = temp->next;
      }
      cur->next = temp->next;
      free(temp);
      }

      Delete
    2. How to find middle node from double linked list.When we are passing start address and last node address.

      Delete
    3. What is use of conditional variable with mutex operation.

      Delete
    4. Hi Raghwendra
      To Finding a middle node in doubly list is quite easy when you are passing Start and Last node address. But one thing we should keep in mind in order to finding a middle node. Middle node certain in case of DLL with odd number of nodes. where as in even number of nodes DLL, Situation is changed. So to meet all odd even nodes issue we need to put two conditions


      while ( start != NULL && end != NULL)
      {
      if ( start == end )
      {
      // Any of node either start or end, can be middle node
      // Because both are pointing same node. i.e middle node
      } else if ( start->prev == end->next) {
      // Any of node either start or end, can be middle node. Because this condition will become true only when it is a even node DLL
      }
      start = start->next;
      end = end->prev;
      }

      Delete