insert element at middle in Doubly Link List Implementation
/* Function to insert element at position */ public void insertAtPos(int val , int pos) { Node nptr = new Node(val, null, null); if (pos == 1) { insertAtStart(val); return; } Node ptr = start; for (int i = 2; i <= size; i++) { if (i == pos) { Node tmp = ptr.getLinkNext(); ptr.setLinkNext(nptr); nptr.setLinkPrev(ptr); nptr.setLinkNext(tmp); tmp.setLinkPrev(nptr); } ptr = ptr.getLinkNext(); } size++ ; }
for more details Click Here
No comments:
Post a Comment