Im trying to remove all people from the list who have the same course name in my custom LinkedList class. I have managed to get my programme to delete people individually based on number however can not figure out how to remove multiple at once. I have browsed online for any solutions and have tried multiple so far but none
Tag: linked-list
Why this linked list rear operation snippet code throws error?
in the below snippet code contains 3 files, named main which is the main operation code, node file contains LinkedList creation and methods contains the linked list operation. In the add rear section throws error.. while execution. I have added the snippet error screshoot Main.java node.java Methods.java Execution Output Image Answer few mistakes here : need to initialise ‘methods’ outside
Adding two linked list ends in Infinite Loop
I’m trying to solve LeetCode problem 2. Add Two Numbers: You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each of their nodes contains a single digit. Add the two numbers and return the sum as a linked list. You may assume the two numbers do not contain any leading
How can I loop through a linked list and print each piece of data that matches the input?
I’m working on this method but am running into an issue. When I enter a word that matches the data in an index of the linked list, it only prints the first index of the Linked List the same number of times that the word I entered appears in the entire linked list. For example: The linked list contains these
Selection sort with LinkedList in Java
I would like to implement selection sort using LinkedList in Java. I know how to do it with ArrayList, please don’t comment that I should use it instead. I am interested in demonstrating the advantages (fast insertion and removal) and disadvantages of linked lists compared to arrays. I know how to do this in C where I have pointers and
Initialize a Linked List nodes using map().reduce()
I want to do this initialization of the Node class using java streams. How do I do this using the map and reduce stream operations? I’ve tried something like this, which does not compile I want to map each element in the array to Node(int i , Node n) and then reduce it to a Node. What am I missing
Removing Duplicates from linked list. Why are the position of “prev = head” and “p2 = p2.next” not outside the else statement?
For the first function, shouldn’t “prev = head” be outside of else because we want to set the previous every time before we change the head value? For the second function, shouldn’t “p2 = p2.next” be outside of else because we want to go next every time? Thank you guys. Answer Shouldn’t “p2 = p2.next” be outside of else because
peek and element in Java’s LinkedList
What is the difference between peek and element in Java’s LinkedList? Here is what the Oracle Java Documentation page describes them to be, but they do not explain the difference. public E peek() Retrieves, but does not remove, the head (first element) of this list. Specified by: peek in interface Deque<E> Specified by: peek in interface Queue<E> Returns: the head
Simple Linked List: getting an ‘error – found cycle’ in code
I have this reverseList function: But I get an error that says ‘found cycle in the LinkedList’ when iterating specifically through ‘curr.next = prev’ and ‘prev = curr’. Any ideas on why this might be occuring? Thanks Answer As far as I can tell you are testing your code with some kind of judge since there is no “found cycle”
Couldn’t implement binary search on linked list
i am a cse student who takes data structures course. Trying to implement binary search algorithm to my SinglyLinkedList class, somehow i’ve failed. Could you check it what’s wrong please ? The related method; I’ve debugged and it just enters the loops this side: else if(temp.getElement() > target) All class for better understanding; And the main method; It returns; Answer