I am given the pointer to the head node of a linked list, an integer to add to the list and the position at which the integer must be inserted. After inserting this node at the desired position I need to return the head node. The code that I have written is not working for some reason and goes in
Tag: linked-list
Comparing two linked lists and returing a list with maximum values
I am planning to write a Java Function that takes two linked lists. Both have the same size. I want to return a new list that contains the maximum of the data found in the corresponding nodes of the two lists passed to my function. However I am stuck in filling the new list. I came up with this: I
How would I find the length of a linkedlist IN a linkedlist?
I’m trying to go through a linkedlist(which we can call the superlist) which has elements of linked lists(sublists) within it. The method that adds the elements into both linked lists is: Now I have to write methods to check if there are groups of 1, 2, 3, 4 elements in the sublists by traversing the superlist What I have so
LinkedList remove at index java
I’ve made a remove method from scratch that removes a Node from a linked list at a specified index. It’s not removing the correct Node. I’ve tried to step through with the debugger in eclipse but couldn’t catch the problem. Each Node contains a token. I have included the Token class, Node class. I have written my methods in the
Java, comparing a Linked List to an Array
Working on a Java program that will read in two different passages, convert both strings to arrays of strings for each word, and then String One to a linked list, which will promptly be sorted into alphabetical order. After the list has been sorted, I get confused. I have a for loop written to get the length of array2 to
Removing values from a custom LinkedList class
This custom class mimics the functionality of Java’s LinkedList Class except it only takes integers and obviously lacks most of the functionality. For this one method, removeAll(), I am to go through each node for the list and remove all nodes with that value. My problem is that when the first node in the list contains the value to be
How do you remove the first Node in a Linked List?
Sup guys so I’m going over a few of my methods in my Linked List class and I’m getting a logical error when removing a node from a linked list. I was working on my removeFirst() method when I then encountered a error in my removeLast() method as well. The problem is that both remove the last item in the
Array of LinkedList adding new nodes
I’ve created an array (using the second answer from this method) by: public static LinkedList[] map; … // later …. map = (LinkedList[]) new LinkedList[count]; …
How to remove certain items from a Stack [closed]
It’s difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 9 years ago. I have a homework problem in which I need to remove all the
LinkedList: java.lang.OutOfMemoryError: Java heap space
I’m trying to make a graph implementation for an assignment, which has Graph(GraphImp) objects and Node(NodeImp) objects. Node objects contain a reference to their Graph, x & y co-ordinates and a name. The Graph object contains a linked list of its Nodes. The problem occurs when I try to add a Node into the middle of the List of Nodes