Skip to main content

All Questions

1 vote
1 answer
129 views

What happens to the lost part of a singly Linked list when I am introducing a loop at the middle?

I have created a singly linked list, and this is how it looks after displaying it: 19-->85-->50-->20-->33-->9-->1-->7-->null I have created a method that can add a node to a ...
NV basnayaka's user avatar
1 vote
2 answers
138 views

Java: Inserting node at the end of a LinkedList

I am currently learning Java and data structures, and I am trying to use insertion to insert the values in a double array to a LinkedList by only inserting each element at the end of the list. I've ...
rzan1's user avatar
  • 37
0 votes
1 answer
43 views

Bug while Swapping a LinkedList

Here I am trying to Swap the Head and tail of a singly Linked list public void reversePI() { Node N1 = this.tail; Node Helper = this.head.next; this.tail = this.head; ...
Fam fas's user avatar
  • 37
-1 votes
2 answers
533 views

Remove consecutive nodes in Single-Linked List

Can anyone help me figure it out? I create a method called remainingNodes() in the SingleLinkedList class to count remaining nodes after removing all consecutive nodes of same value in a single-linked ...
Tnhan02's user avatar
0 votes
1 answer
146 views

infinite loop, LeetCode 1721

here's my code : class Solution { public int size (ListNode head) { int size = 0; ListNode curr = head; while (curr != null) { size ++; ...
batsiouny's user avatar
0 votes
1 answer
47 views

Deleting N nodes after M nodes in a Singly Linked List

Given a linked list, delete N nodes after skipping M nodes of a linked list until the last of the linked list This is the Java program I wrote to solve this problem. For certain large test cases it's ...
userUser's user avatar
0 votes
1 answer
157 views

Returning the middle node in a singly Linked List (Java)

I've forgotten basically everything from my DSA class because I'm an idiot, so I'm spending winter break refreshing myself and doing practice problems I find online. One of them is returning the ...
deprexit's user avatar
0 votes
4 answers
966 views

Insert after specific element in LinkedList java

I was trying to write the function insertAfter to insert the element after specific element in the LinkedList . Below is the code. The insertAfter function is not producing the desired output. Can ...
isilia's user avatar
  • 361
0 votes
1 answer
178 views

Why is a node not updated by setting curr pointer?

I am working with code that is to rearrange a linked list, such that nodes are taken from the front and back of the list in alternating fashion, and so convert a list of 1->2->3->4->5->...
srinjay ayan's user avatar
1 vote
2 answers
382 views

Reversed linked list - Issue with logic

I'm working on the following problem Reverse Linked List from Leetcode: Given the head of a singly linked list, reverse the list, and return the reversed list. Class ListNode defined as follows: ...
leavejimmyalone's user avatar
-1 votes
2 answers
258 views

Singly Linked List pass by value

Hi i am learning linked list in java. Its a simple doubt but couldn't figure out. class Node{ int data; Node next; Node(int data){ this.data = data; this.next = null; } //java main method Node head = ...
Skillkrio's user avatar
0 votes
2 answers
487 views

How to print the linkedlist from the middle node to the last node?

I'm trying to solve the LeetCode problem 876. Middle of the Linked List: Given the head of a singly linked list, return the middle node of the linked list. If there are two middle nodes, return the ...
abhishek kumar's user avatar
0 votes
0 answers
15 views

How to print linked list nodes while traversing? [duplicate]

I tried printing below code (temp): public void insert(int val, int index){ if(index == 0){ insertFirst(val); return; } if(index == size){ insertLast(val); ...
Harsha Happyness's user avatar
0 votes
1 answer
72 views

which comes first while reversing a linked list recursively?

So, I was learning DSA in java and came to reversing a linked list. I understood the iterative method, but while learning the recursive method there was a point in time where the recursion does two ...
VIKING's user avatar
  • 5
-1 votes
2 answers
289 views

Can nodes other than the head or the tail be null in a LinkedList?

My understanding is. If the head is null, the list is empty. If the tail is null, we have reached the end of the list. So, my question is, In a LinkedList a-b-c-d-null can either a b c and d be null ...
Bikash Adhikari's user avatar

15 30 50 per page
1
2 3 4 5 6