GeeksforGeeks » Linked List specific questions

deletion from circular linked list

(6 posts)

Tags:

  1. cll
    guest
    Posted 1 year ago #

    You are given a circular single linked list of sufficiently many number of nodes(say more than 1 crore). You need to delete a node say P and you are given a pointer to P in the circular single list. Suggest the most efficient methodology of deleting the node P from the circular single linked list.

  2. mdasif
    guest
    Posted 1 year ago #

    Copy the data of next node into this and remove the next node.

          p.data = p.next.data;
          Node deletedNode = p.next;
          p.next = p.next.next;
          free(deletedNode)
    
  3. deepanker.aggarwal
    Member
    Posted 7 months ago #

    mdasif .....what if p is the last node

  4. sk
    guest
    Posted 7 months ago #

    only take two condition :-

    1st if p is head node
    2nd if p is last node
    else for other it'll go simple deletion.

  5. Ramana
    guest
    Posted 6 months ago #

    If p is head node it wont make a difference but if p is the last node it will make a difference.

    this code will work

    q=p->next;
    p->info=q->info;
    p->next=q->next;
    free(q);
    q=NULL;
    If(p->next=header)
    {
      header=p;
    }
    
  6. ramanadeepsingh
    Member
    Posted 6 months ago #

    nice


Reply

You must log in to post.

RSS feed for this topic