Skip to content
Advertisement

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

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

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

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

Advertisement