have been given a singly linked list of integers. Write a function that returns the index/position of integer data denoted by 'N' (if it exists). Return -1 otherwise. Note :Assume that the Indexing for the singly linked list always starts from 0.Input format :The first line contains an Integer 'T' which denotes the number of test cases. The first line of each test case or query contains the elements of the singly linked list separated by a single space. The second line contains the integer value 'N'. It denotes the data to be searched in the given singly linked list. Remember/Consider :While specifying the list elements for input, -1 indicates the end of the singly linked list and hence -1 would never be a list element. Output format :For each test case, return the index/position of 'N' in the singly linked list. Return -1, otherwise. Output for every test case will be printed in a separate line. Note: You do not need to print anything; it has already been taken care of. Just implement the given function. Constraints :1 <= T <= 10^20 <= M <= 10^5 Where 'M' is the size of the singly linked list. Time Limit: 1 secSample Input 1:23 4 5 2 6 19-1510 20 30 40 50 60 70-16Sample Output 1 :2-1 Explanation for Sample Output 1:In test case 1, 'N' = 5 appears at position 2 (0-based indexing) in the given linked list. In test case 2, we can see that 'N' = 6 is not present in the given linked list. Sample Input 2:21 -1234 52619-16Sample Output 2:-14 Explanation for Sample Output 2:In test case 1, we can see that 'N' = 2 is not present in the given linked list. In test case 2, 'N' = 6 appears t position 4 (0-based indexing) in the given linked list.Solutions://///// ***** Following is the class structure of the Node class: class LinkedListNode { T data; LinkedListNodenext; public LinkedListNode(T data) { this.data = data; } } ************/ public class Solution { public static int findNode(LinkedListNode head, int n) { LinkedListNode node = head; int count=0; while (node!=null) { if (node.data==n) { return count; } else { node=node.next; count++; } } ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
have been given a singly linked list of integers. Write a function that returns the index/position of integer data denoted by 'N' (if it exists). Return -1 otherwise. Note :Assume that the Indexing for the singly linked list always starts from 0.Input format :The first line contains an Integer 'T' which denotes the number of test cases. The first line of each test case or query contains the elements of the singly linked list separated by a single space. The second line contains the integer value 'N'. It denotes the data to be searched in the given singly linked list. Remember/Consider :While specifying the list elements for input, -1 indicates the end of the singly linked list and hence -1 would never be a list element. Output format :For each test case, return the index/position of 'N' in the singly linked list. Return -1, otherwise. Output for every test case will be printed in a separate line. Note: You do not need to print anything; it has already been taken care of. Just implement the given function. Constraints :1 <= T <= 10^20 <= M <= 10^5 Where 'M' is the size of the singly linked list. Time Limit: 1 secSample Input 1:23 4 5 2 6 19-1510 20 30 40 50 60 70-16Sample Output 1 :2-1 Explanation for Sample Output 1:In test case 1, 'N' = 5 appears at position 2 (0-based indexing) in the given linked list. In test case 2, we can see that 'N' = 6 is not present in the given linked list. Sample Input 2:21 -1234 52619-16Sample Output 2:-14 Explanation for Sample Output 2:In test case 1, we can see that 'N' = 2 is not present in the given linked list. In test case 2, 'N' = 6 appears t position 4 (0-based indexing) in the given linked list.Solutions://///// ***** Following is the class structure of the Node class: class LinkedListNode { T data; LinkedListNodenext; public LinkedListNode(T data) { this.data = data; } } ************/ public class Solution { public static int findNode(LinkedListNode head, int n) { LinkedListNode node = head; int count=0; while (node!=null) { if (node.data==n) { return count; } else { node=node.next; count++; } } ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Hold on to do asap.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education