diff --git a/guide/english/computer-science/data-structures/linked-lists/index.md b/guide/english/computer-science/data-structures/linked-lists/index.md index 0bfab23592..6df55c6a12 100644 --- a/guide/english/computer-science/data-structures/linked-lists/index.md +++ b/guide/english/computer-science/data-structures/linked-lists/index.md @@ -90,6 +90,7 @@ class List public: void display(); void insertBefore(int); + void deleteNode(int); List(); }; @@ -119,6 +120,47 @@ void List :: insertBefore(int data) count++; } +void List :: deleteNode(int loc) +{ + //delete first node + if(loc == 1 || count == 1) + { + N *node = new N; + node = head; + head = head->tail; + delete node; + } + //delete last node + else if(loc == count) + { + N *curr = new N; + N *prev = new N; + curr = head; + while(curr->tail != NULL) + { + prev = curr; + curr = curr->tail; + } + prev->tail = NULL; + end = prev; + delete curr; + } + //delete in between + else + { + N *curr=new N; + N *prev=new N; + curr=head; + for(int i=1;itail; + } + prev->tail=curr->tail; + } + count--; +} + void List :: display() { cout<<"Number of nodes in the list = "<