We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Delete a Node
Delete a Node
+ 0 comments public static SinglyLinkedListNode deleteNode(SinglyLinkedListNode llist, int position) { if (position == 0) { return llist.next; } SinglyLinkedListNode n = llist; int counter = 0; while(counter <= position) { if(counter == position -1) { if(n.next == null) { return llist; } n.next = n.next.next; return llist; } n = n.next; counter++; } return llist; }
+ 0 comments c lang
SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) { if((position) == 0) { return llist->next; } llist->next = deleteNode(llist->next, position-1); return llist; }
+ 0 comments c language
SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) { int count=0; if(llist==NULL){ return NULL; } if(position==0){ return llist->next; } SinglyLinkedListNode* temp=llist; SinglyLinkedListNode* prev=NULL; while (temp!=NULL) { if(count==position){ prev->next=temp->next; free(temp); } count++; prev=temp; temp=temp->next; } return llist; }
+ 0 comments def deleteNode(llist, position): if position==0: return llist.next if llist==None: return None else: temp =llist temp2=llist.next for i in range(position-1): temp=temp.next temp2=temp2.next temp.next=temp2.next return llist
+ 0 comments INCLUDE INCLUDE SinglyLinkedListNode* deleteNode(SinglyLinkedListNode* llist, int position) {
SinglyLinkedListNode*ptr=llist; if (position==0) { return llist->next; } position=position-1; if (llist==NULL) { return llist;
} while (position--){ ptr=ptr->next; } SinglyLinkedListNode*privious=ptr; ptr=ptr->next; privious->next=ptr->next; // free(ptr); delete ptr; return llist; }
Load more conversations
Sort 721 Discussions, By:
Please Login in order to post a comment