Insert an element at kth position from the end of linked list. Return true if success and
Question:
Insert an element at kth position from the end of linked list. Return true if success and if list is not long enough, then return -1. Take a pointer of head and then advance it by K steps forward, then take another pointer and then advance both simultaneously, so that when the first pointer reaches the end of a linked list then second pointer is at the point where you need to insert the node.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Related Book For
Problems Solving In Data Structures And Algorithms Using C++
ISBN: 9789356273177
2nd Edition
Authors: Hemant Jain
Question Posted: