Any suggestions? Remove Nth Node from List End - Given a linked list, remove the nth node from the end of list and return its head. It contains well written, well thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Questions. When you fill the array, wrap around and overwrite the elements you stored before. Initialize count = 0 2. dark feminine secrets. For a non-square, is there a prime number for which it is a primitive root? Given the head of a linked list, remove the n th node from the end of the list and return its head. Isn't this what the implementation in the question does? Calculate the length of the Linked List. Return the main pointer.Below image is a dry run of the above approach: Space complexity: O(1) since using constant space. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. Now move both pointers one by one until the reference pointer reaches the end. Print the (len n + 1)th node from the beginning of the Linked List. 2) Print the (len n + 1)th node from the beginning of the Linked List. As a result NthNode points to nth node from the end of the linked list. Voc est aqui: define antivirus with example / university of south bohemia faculty of science / geeksforgeeks c programming practice - Simple FET Question. Declare a length variable. I agree that this is a good algorithm for my supplied code. Check our Website: https://www.takeuforward.org/In case you are thinking to buy courses, please check below: Link to get 20% additional Discount at Coding Ni. Not the answer you're looking for? Step 1: First, let's take two pointers to suppose pointer1 and pointer2. acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Full Stack Development with React & Node JS (Live), Preparation Package for Working Professional, Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Remove Nth node from end of the Linked List, An Uncommon representation of array elements, Delete a Linked List node at a given position, Find Length of a Linked List (Iterative and Recursive), Search an element in a Linked List (Iterative and Recursive), Write a function that counts the number of times a given int occurs in a Linked List, Add two numbers represented by linked lists | Set 1, Introduction to Stack - Data Structure and Algorithm Tutorials, Find the nth node from the end of the linked list, If length < B, then we cant remove the node. When the first pointer reaches the end, second pointer will give the answer. problem statement, we would basically tracking the Nth Circular Linked List : Insert a node at the end of a circular linked list : ----- Input the number of nodes : 3 Input data for node 1 : 2 Input data for node 2 : 5 Input data for node 3 : 8 Data entered in the list are : Data 1 = 2 Data 2 = 5 Data 3 = 8 Input the data to be inserted : 9 After insertion the new list are : Data 1 = 2 Data 2 = 5 . Example: Input: 1->10->30->14, index = 2 Output: 30 The node at index 2 is 30 Recommended Practice Node at a given index in linked list Try It! Now add nodes to the linked list. Example 1: Input: 1 -&gt; 3 -&gt; 4 &nbsp; x = 3 Output: 1 -&gt; 3 Explanation: After deleting the node at 3rd position (1-base in Making statements based on opinion; back them up with references or personal experience. Your edit improved things quite a bit :) . In this article, we have explained two approaches to Remove N-th Node from end of Singly Linked List. Let the length be len. XOR Linked List - Find Nth Node from the end, Java Program For Printing Nth Node From The End Of A Linked List(Duplicate), C++ Program For Printing Nth Node From The End Of A Linked List, Cpp14 Program For Printing Nth Node From The End Of A Linked List (Duplicate), Recursive Approach to find nth node from the end in the linked list, Java Program For Printing Nth Node From The End Of A Linked List, Delete Nth node from the end of the given linked list, Program for Nth node from the end of a Linked List, XOR linked list- Remove first node of the linked list, XOR Linked List: Remove last node of the Linked List, Python Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Javascript Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, C++ Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Java Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Swap Kth node from beginning with Kth node from end in a Linked List, Swap Kth node from beginning with Kth node from end in a Doubly Linked List, C Program For Writing A Function To Get Nth Node In A Linked List, C++ Program For Writing A Function To Get Nth Node In A Linked List, C# Program For Writing A Function To Get Nth Node In A Linked List, Java Program For Writing A Function To Get Nth Node In A Linked List, Python Program For Writing A Function To Get Nth Node In A Linked List, Write a function to get Nth node in a Linked List, Javascript Program For Writing A Function To Get Nth Node In A Linked List, Complete Interview Preparation- Self Paced Course, Data Structures & Algorithms- Self Paced Course. The questioner has a chance of cache hits, if n is small enough that n nodes fit in (some level of) cache. is "life is too short to count calories" grammatically wrong? In our approach, we will define 2 pointers, fast pointer and slow pointer.Algorithm: Time complexity: O(N) where N is no of nodes in linked list, Space complexity: O(1) because using constant variables. This seems to be returning the correct answer, but I'm not sure if this is really the best way to go about things. Lets K be the total nodes in the linked list. Stack Overflow for Teams is moving to its own domain! What is the difference between the root "hemi" and the root "semi"? Example 1: Input: N = 2 LinkedList: 1->2->3->4->5->6->7->8->9 Output: 8 Explanation: In the first example, there are 9 nodes in linked list and we need to find 2nd node from end. 4. And if we wish to change value of a pointer (i. e., it should start pointing to something else), we pass pointer to a pointer. Example 1: Input: N = 2 LinkedList: 1->2->3->4->5->6->7->8->9 Output: 8 Explanation: In the first example, there are 9 nodes in linked list and we need to find 2nd node from end. How to determine length or size of an Array in Java? First count the number of nodes in the list. element starting from the end of linked list. Use two pointer pTemp and NthNode. Connect and share knowledge within a single location that is structured and easy to search. To learn more, see our tips on writing great answers. Auxiliary Space: O(n) for call stack because using recursion. 2. . geeksforgeeks c programming practice. Again traverse the linked list and Return (length - N + 1)th node from the head. Call a user-defined function to calculate the nth node from the end of the linked list. In our approach, first, we evaluate the length of the linked list, then check. The dummy node is taken to handle the edge case where B=N(size of the LinkedList), Start traversing until the fast pointer reaches the nth node, Start traversing by one step both of the pointers until the fast pointers reach the end, When the traversal is done, delete the next node to slowPtr. A Computer Science portal for geeks. Indeed, sorry I was unclear. (also non-attack spells), Can I Vote Via Absentee Ballot in the 2022 Georgia Run-Off Election. So it is always an O(n) solution. If we wish to change the value of a variable by a function, we pass pointer to it. (You could make the stack a little smarter by only storing n elements and dropping them off the bottom of the stack as new ones are added; then you're only using enough space to store n Nodes.). is that different to his current solution? Let the length be len. Finding the "Nth node from the end" of a linked list, embedded.com/electronics-blogs/embedded-round-table/4419407/. Please refer complete article on Program for nth node from the end of a Linked List for more details! Delete a node from the linked list. For example, if the given Linked List is 10->15->20->25 and we add an item 5 at the front, then the Linked List becomes 5->10->15->20->25. In our approach, first, we evaluate the length of the linked list, then check. I don't agree that "first N elements have to be visited twice". Is // really a stressed schwa, appearing only in stressed syllables? Then you'd be walking the end of the list twice, instead of the beginning. Please use ide.geeksforgeeks.org, When making ranged spell attacks with a bow (The Ranger) do you use you dexterity or wisdom Mod? The last node has a reference to null. Please write comments if you find the above codes/algorithms incorrect, or find other ways to solve the same problem. Convert a String to Character Array in Java. Thus, the 2 nd node from the end is the (6 - 2 + 1) = 5 th node from the beginning (6 is the size of the linked list mentioned in example 1). If there is already an element there in the list then we are going to traverse the list to the end and then we are making a connection to that newnode. Print the (len - n + 1)th node from the beginning of the Linked List. A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you have the best browsing experience on our website. if a driver unexpectedly pulls in front of you: trustworthy crossword clue 6 letters; ocean alkalinity enhancement; how do i cancel my union membership Example 1: Input: head = [1,2,3,4,5], n = 2 Output: [1,2,3,5] Example 2: Input: head = [1], n = 1 Output: [] Example 3: Input: head = [1,2], n = 1 Output: [1] Constraints: The number of nodes in the list is sz. Take two Node slowPtr and fastPtr, such that next points to the head, Take one Node to store the head, initially its a dummy node(start), and the next of the node will be pointing to the head. class Solution: def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode: fast, slow = head, head for _ in range(n): fast = fast.next if not fast: return head.next while fast.next: fast, slow = fast.next, slow.next slow.next = slow.next.next return head Java Code: ( Jump to: Problem Description || Solution Idea) generate link and share the link here. N th node from the end is the (s - n + 1)th node from the beginning, where is the total number of nodes present in the linked list. Table of contents: Introduction to Linked List Approach 1: Making two passes through Linked List Approach 2: Going through the list once, one pass It seems like I'm visiting the first n nodes too many times. With your algorithm, the whole list has to fit in cache in order to get any cache hits at all. If N is large then the second loop will be small. Each node of a list is made up of two items - the data and a reference to the next node. @factcodejava: Mike is right - it's a ring buffer that stores the last N entries. Every time you visit a node store it in the current index of the array and advance the array pointer. NADOS also enables doubt support, career opportunities and contests besides free of charge content. Double pointer concept : First pointer is used to store the address of the variable and second pointer used to store the address of the first pointer. Then traverse again, counting off n less nodes. Maintain 2 pointers n nodes apart. A linked list is a linear data structure where each element is a separate object. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that. Your implementation has chosen the first, at the advantage of no extra memory use (other than a couple temporary variables). Remove Nth node from the back of the LL : Delete the middle node of LL : Sort LL : . This has the disadvantage of storing the list in memory twice. We can do this in single pass / one traversal in O (N) time. Your running time is still O(n), so I don't see that there's any problem with it. Writing code in comment? Step 2: Intially initialize these two pointers with the head of the linked list. After removing the second node from the end, the linked list becomes 1->2->3->5. Given a Linked List and a number N, write a function that returns the value at the Nth node from the end of the Linked List. 504), Hashgraph: The sustainable alternative to blockchain, Mobile app infrastructure being decommissioned, Finding the nth to last node in a single linked list using recursion, Understanding the while loop condition in how to find the middle node in a linked list, Cloning a linked list where each node has a random pointer to any other node in linked list, Rebuild of DB fails, yet size of the DB has doubled, NGINX access logs from single page application, How do I rationalize to my players that the Mirror Image is completely useless against the Beholder rays? Remove Nth Node From End of List - Solution in Python Problem Given the head of a linked list, remove the nth node from the end of the list and return its head. But I feel the pseudo code make it clearer. Write a function to get Nth node in a Linked List Write a GetNth () function that takes a linked list and an integer index and returns the data value stored in the node at that index position. Please refer complete article on Program for nth node from the end of a Linked List for more details. Now, we are linking the last element pointer to the newnode. Space Complexity: O(1) because using constant space for pointer manipulation. When the 1st pointer reaches the tail, the second pointer will be pointing to the desired node. 2. Then it's constant memory, still O(n), still walking the end of the list twice. Let the length be len. This has to be done with a singly linked list. Now move both pointers one by one until the reference pointer reaches the end. 1 <= sz <= 30; 0 <= Node.val <= 100; 1 <= n <= sz acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Full Stack Development with React & Node JS (Live), Preparation Package for Working Professional, Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Applications, Advantages and Disadvantages of Linked List, Find Length of a Linked List (Iterative and Recursive), Find length of loop/cycle in given Linked List, Write a function to get the intersection point of two Linked Lists, Check if a linked list is Circular Linked List, Convert singly linked list into circular linked list, Josephus Circle implementation using STL list, Check if two Circular Linked Lists are identical, Delete all odd nodes of a Circular Linked List, Doubly Linked List | Set 1 (Introduction and Insertion), Applications, Advantages and Disadvantages of Doubly Linked List, Delete a Doubly Linked List node at a given position, Reverse a Doubly Linked List | Set 4 (Swapping Data), Check if a doubly linked list of characters is palindrome or not, Skip List | Set 3 (Searching and Deletion), Unrolled Linked List | Set 1 (Introduction), Program for Nth node from the end of a Linked List, Search an element in a Linked List (Iterative and Recursive), Print reverse of a Linked List without actually reversing, Iteratively Reverse a linked list using only 2 pointers (An Interesting Method), Reverse a Linked List in groups of given size, Reverse alternate K nodes in a Singly Linked List, Insert a node after the n-th node from the end, Delete a Linked List node at a given position, Remove duplicates from an unsorted linked list, Delete N nodes after M nodes of a linked list, Delete last occurrence of an item from linked list, Remove all occurrences of duplicates from a sorted Linked List, Remove every k-th node of the linked list, Rearrange a linked list such that all even and odd positioned nodes are together, Rearrange a Linked List in Zig-Zag fashion, Rearrange a given list such that it consists of alternating minimum maximum elements, Write a function that counts the number of times a given int occurs in a Linked List, Merge a linked list into another linked list at alternate positions, In-place Merge two linked lists without changing links of first list, Union and Intersection of two Linked Lists, Clone a Linked List with next and Random Pointer, A Programmers approach of looking at Array vs. Writing code in comment? Given a linked list consisting of L nodes and given a number N. The task is to find the Nth node from the end of the linked list. If this condition satisfies that's means we are at the end of the array. Refer TextBook : "Data Structure and Algorithms Made Easy in Java". Double pointer concept : First pointer is used to store the address of the variable and second pointer used to store the address of the first pointer. Approach: Deleting the Bth node from last is basically the same as deleting (length-B+1) from the start. With a simple observation we can understand that the first element will be the smallest number (low) in the matrix and the last number say , high (matrix[n-1][n-1] , n bring length of matrix</b>) will be the highest. static int i; public static void NthToLast(LinkedListNode head, int n) { if (head == null) return; NthToLast(head.Next, n); i++; if (n == i) { Console.WriteLine("Mth to last" + head.Data); return; } } Calculate the length of Linked List. Now the main pointer will point to nth node from the end. By using our site, you Still an O(n) algorithm, that's unavoidable. Example 2: older men younger shemale sex; tmodloader mobile. vissel kobe vs avispa fukuoka prediction minecraft splash text resource pack. Time Complexity: O(n) where n is the length of linked list. Initialize both reference and main pointers to head. Does English have an equivalent to the Aramaic idiom "ashes on my head"? Master Data Structures concepts such as Linked Lists, Heaps, DP, Graphs, Arrays & more. Java Program For Printing Nth Node From The End Of A Linked List(Duplicate), Cpp14 Program For Printing Nth Node From The End Of A Linked List (Duplicate), Java Program For Printing Nth Node From The End Of A Linked List, Program for Nth node from the end of a Linked List, XOR Linked List - Find Nth Node from the end, Recursive Approach to find nth node from the end in the linked list, Remove Nth node from end of the Linked List, Delete Nth node from the end of the given linked list, Python Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Javascript Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, C++ Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Java Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Swap Kth node from beginning with Kth node from end in a Linked List, Swap Kth node from beginning with Kth node from end in a Doubly Linked List, C++ Program For Printing Reverse Of A Linked List Without Actually Reversing, C# Program For Printing Reverse Of A Linked List Without Actually Reversing, Javascript Program For Printing Reverse Of A Linked List Without Actually Reversing, Java Program For Printing Reverse Of A Linked List Without Actually Reversing, Python Program For Printing Reverse Of A Linked List Without Actually Reversing, C Program For Printing Reverse Of A Linked List Without Actually Reversing, C Program For Writing A Function To Get Nth Node In A Linked List, C++ Program For Writing A Function To Get Nth Node In A Linked List, C# Program For Writing A Function To Get Nth Node In A Linked List, Java Program For Writing A Function To Get Nth Node In A Linked List, Complete Interview Preparation- Self Paced Course, Data Structures & Algorithms- Self Paced Course. Initialize count = 0 2. Fighting to balance identity and anonymity on the web(3) (Ep. But this also is just an O(n) algorithm. And if we wish to change the value of a pointer (i. e., it should start pointing to something else), we pass the pointer to a pointer. Some other interesting problems in Linked List, Java Program For Printing Nth Node From The End Of A Linked List(Duplicate), C++ Program For Printing Nth Node From The End Of A Linked List, Cpp14 Program For Printing Nth Node From The End Of A Linked List (Duplicate), Java Program For Printing Nth Node From The End Of A Linked List, XOR Linked List - Find Nth Node from the end, Recursive Approach to find nth node from the end in the linked list, Remove Nth node from end of the Linked List, Delete Nth node from the end of the given linked list, Python Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Javascript Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, C++ Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Java Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Swap Kth node from beginning with Kth node from end in a Linked List, Swap Kth node from beginning with Kth node from end in a Doubly Linked List, C Program For Writing A Function To Get Nth Node In A Linked List, C++ Program For Writing A Function To Get Nth Node In A Linked List, C# Program For Writing A Function To Get Nth Node In A Linked List, Java Program For Writing A Function To Get Nth Node In A Linked List, Python Program For Writing A Function To Get Nth Node In A Linked List, Javascript Program For Writing A Function To Get Nth Node In A Linked List, Write a function to get Nth node in a Linked List, XOR linked list- Remove first node of the linked list, Create new linked list from two given linked list with greater element at each node, Complete Interview Preparation- Self Paced Course, Data Structures & Algorithms- Self Paced Course. Linked Lists are used to create trees and graphs. generate link and share the link here. 53.4%: . Example 1: Input: N = 2 LinkedList: 1->2->3->4->5->6->7->8->9 Output: 8 Explanation: Each node consists of its own data and the address of the next node and forms a chain. Why is a Letters Patent Appeal called so? 1) Calculate the length of the Linked List. Nice alternative. Find centralized, trusted content and collaborate around the technologies you use most. limping crossword clue 4 letters; vintage culture coachella; pan critique crossword clue; tale intended to arouse pity crossword clue; 2. Method 1: For finding out 'n'th node from the end, find the length of given linked list (say lengthOfList) and return (lengthOfList - n + 1)th node from the beginning. Transversal is much easier, since you can start at the end and work your way to the beginning. 1 <= sz <= 30; 0 <= Node.val <= 100; 1 <= n <= sz take two pointers p1,p2 Also, you gave me a suggestion, and not an algorithm of what I already did in code :). its very simple.. Linked list elements are not stored at contiguous location; the elements are linked using pointers. Input : 1->2->3->4->5 , N = 2Output : 1->2->3->5, Input : 7->8->4->3->2 , N = 1Output : 7->8->4->3, Prerequisites:1. Checking whether temp->next!=NULL or not. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. If length = B, then return head->next. Please use ide.geeksforgeeks.org, Below is a recursive code for the same method. Given the head of a linked list, remove the n th node from the end of the list and return its head. The entry point into a linked list is called the head of the list. Print the (len n + 1)th node from the beginning of the Linked List. I am using a static variable 'i' which will be incremented For example in the following list of length 7, to return 2nd node from the end (n = 2), we need to return 6th (7 - 2 + 1) node from beginning which is node '6'. Note that I have to do this with a singly linked list. could you launch a spacecraft with turbines? What do you call a reply or comment that shows great quick wit? Like: 1. Like in the acknowledge that you have read and understood our, Data Structure & Algorithm Classes (Live), Full Stack Development with React & Node JS (Live), Preparation Package for Working Professional, Full Stack Development with React & Node JS(Live), GATE CS Original Papers and Official Keys, ISRO CS Original Papers and Official Keys, ISRO CS Syllabus for Scientist/Engineer Exam, Initialize a vector in C++ (7 different ways), Map in C++ Standard Template Library (STL), Set in C++ Standard Template Library (STL), Left Shift and Right Shift Operators in C/C++, Priority Queue in C++ Standard Template Library (STL), Different Methods to Reverse a String in C++, Program for nth node from the end of a Linked List, C++ Program to Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed, C++ Program For Pointing Arbit Pointer To Greatest Value Right Side Node In A Linked List. Initialize both reference and main pointers to head. Thanks to Anuj Bansal for providing the following code. Is "Adversarial Policies Beat Professional-Level Go AIs" simply wrong? Now move both pointers one by one until the reference pointer reaches the end. Find the nth node from the end of the linked list. Start an two pointers. To answer the question, there is no other go as first N elements have to be visited twice. Writing code in comment? If we wish to change the value of a variable by a function, we pass a pointer to it. Below is the implementation of the above approach: Auxiliary Space: O(1) since using constant space. Now the main pointer will point to nth node from the end. Thus, the approach is simple. Input: 35 -> 15 -> 4 -> 20, N = 4Output: 35. See my answer for an alg that visits all nodes exactly once. Observation : The Nth node from the end is (K-N+1)th node from the beginning. First pointer is used to store the address of the variable and the second pointer is used to store the address of the first pointer. Is there a name for that kind of trick? Declare two pointers: pointer1 and pointer2. and when you end, you can comment your end date, experience, mistakes, so that the juniors of the . Java Program For Printing Nth Node From The End Of A Linked List(Duplicate), C++ Program For Printing Nth Node From The End Of A Linked List, Cpp14 Program For Printing Nth Node From The End Of A Linked List (Duplicate), Program for Nth node from the end of a Linked List, Java Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, XOR Linked List - Find Nth Node from the end, Recursive Approach to find nth node from the end in the linked list, Remove Nth node from end of the Linked List, Delete Nth node from the end of the given linked list, Python Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Javascript Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, C++ Program For Swapping Kth Node From Beginning With Kth Node From End In A Linked List, Java Program For Printing Reverse Of A Linked List Without Actually Reversing, Java Program For Writing A Function To Get Nth Node In A Linked List, Swap Kth node from beginning with Kth node from end in a Linked List, Swap Kth node from beginning with Kth node from end in a Doubly Linked List, C++ Program For Printing Reverse Of A Linked List Without Actually Reversing, C# Program For Printing Reverse Of A Linked List Without Actually Reversing, Javascript Program For Printing Reverse Of A Linked List Without Actually Reversing, Python Program For Printing Reverse Of A Linked List Without Actually Reversing, C Program For Printing Reverse Of A Linked List Without Actually Reversing, C Program For Writing A Function To Get Nth Node In A Linked List, C++ Program For Writing A Function To Get Nth Node In A Linked List, C# Program For Writing A Function To Get Nth Node In A Linked List, Complete Interview Preparation- Self Paced Course, Data Structures & Algorithms- Self Paced Course. I think that will work. terraform check if variable is empty string Like in the problem statement, we would basically tracking the Nth element starting from the end of linked list. Maintain two pointers main_ptr and ref_ptr, Move ref_ptr to the Nth node from the start, Now move both main_ptr and ref_ptr, until the ref_ptr reaches the last node, Now print the data of the main_ptr, as it is at the Nth node from the end. 60.7%: Medium: 2130: Maximum Twin Sum of a Linked List. Now the pointer which was moved later points at the Nth node from the end of the Linked-List. 2nd node from end os 8. A-143, 9th Floor, Sovereign Corporate Tower, We use cookies to ensure you have the best browsing experience on our website. By using our site, you Why isn't the signal reaching ground? Example: Input: 1->10->30->14, index = 2 Output: 30 The node at index 2 is 30 Algorithm: 1. So the problem simplifies down to that we have to find (K-N+1)th node from the beginning. Write a GetNth() function that takes a linked list and an integer index and returns the data value stored in the node at that index position.