Questions tagged [linked-list]

A linked list is a data structure in which the elements contain references to the next (and optionally the previous) element.

Filter by
Sorted by
Tagged with
6
votes
3answers
259 views

Rotate List by K places

I am trying to solve the question at :https://leetcode.com/problems/rotate-list/ Question: Given a linked list, rotate the list to the right by k places, where k is non-negative. Example 1:...
3
votes
1answer
39 views

LeetCode #37: Sudoku as Exact Cover Problem solved using Dancing Links

Introduction I provide a regular 9x9 Sudoku solver, reducing the puzzle to an Exact Cover Problem. The algorithm used is Knuth'...
2
votes
1answer
115 views

LinkedList Swift Implementation

Linked List Implementation in Swift Swift 5.0, Xcode 10.3 I have written an implementation for a doubly linked list in Swift. As well, I decided to make the node class private and thus hidden to the ...
5
votes
3answers
487 views

Organizational Tool GUI with Java Swing (and GridBagLayout)

My first 'large' project is to create an organizational tool. Right now, it's pretty basic, but nevertheless functional in terms of the intent of the current release (v0.3.0). My main question is: '...
1
vote
1answer
43 views

Remove Duplicates From Linked List In Place - Java [closed]

This is my implementation ...
5
votes
2answers
95 views

LeetCode: Linked List Cycle

Challenge https://leetcode.com/explore/interview/card/top-interview-questions-easy/93/linked-list/773/ Given a linked list, determine if it has a cycle in it. To represent a cycle in the ...
2
votes
0answers
80 views

Efficient way to fill 2D matrices by rows in a list using R

I have a list of 2D matrices. Each matrix is filled using the function “fillMatrices”. This function adds a number of individuals to each day 0 in a matrix and updates the columns “a_M”, “b_M” and “...
4
votes
1answer
974 views

Linked list implementation of binary heap insertion

Is this a correct linked list implementation of binary heap insertion? This is not a homework exercise. ...
4
votes
3answers
8k views

Circular Singly Linked List using Java

Please review my implementation of a Circular Singly Linked List. ...
2
votes
2answers
63 views

Logger adapter with a configurable chain of responsibility of middlewares

I use my own logger adapter that collects data into a dictionary: public class Log : Dictionary<string, object> { } This is really all I have. I then pass ...
3
votes
0answers
29 views

Circular doubly linked list implementation in Cython

This is a follow-up from my previous question. In summary, I am trying to implement a BVH module with Cython and need a way to keep track of the volumes during the construction of the hierarchy. I ...
2
votes
2answers
64 views

Implementation of a Singularly LinkedList

I'm new to C++ and trying to learn by implementing data structures in it. Is the code below the most efficient way of implementing the data structure in C++? Does it conform to C++ standards, and how ...
4
votes
1answer
32 views

Doubly linked list in Cython

I am implementing a BVH (Bounding volume hierarchy) in Cython and thought of using a doubly linked list to hold reference of the volumes that still need to be split and push new volumes at one end ...
2
votes
1answer
37 views

C++ singly linked list with iterator

I have written a simple singly linked list in C++. I have previously had a data structure in an interview criticised for being too C-like (no iterators and using new/delete) instead of smart pointers. ...
1
vote
1answer
47 views

Insert new middleware at the “right” location

I need to have my logger middlewares (nodes of a linked-list) in the right order so that they complement each other and work as desired. Any known middleware can be inserted anytime but the first and ...
1
vote
1answer
43 views

Reverse a Linked List in place

I am solving some programming challenges for learning Javascript. The challenge I chose is: Given the head of a singly linked list, reverse it in-place. Here is my implementation in JS ...
4
votes
1answer
59 views

Implementing linked list from scratch - Follow up

A follow up for this question: Implementing Linked lists in Python from scratch Node: ...
9
votes
2answers
141 views

Implementing Linked lists in Python from scratch

After finishing my ds and algorithms course I wanted to implement what I've learned through the semester so here is my try for Linked lists, both regular (one way) and double one (two way). code: <...
8
votes
4answers
2k views

Very basic singly linked list

Here is implementation for singly linkedlist. Any suggestions are most welcome ...
5
votes
2answers
2k views

Stack using a Linked List

I thought implementing a stack using a linked list was a good option since an array implementation involves reallocation of array size and so on. I have implemented basic ...
3
votes
3answers
161 views

Singly-linked list queue

I recently learned the core .NET Queue type uses arrays internally, and that this is actually much more efficient. I've had a go at writing a singly-linked list ...
0
votes
1answer
83 views

Adding a Node to the Linked List is taking a longer Time when using a reference to the Tail Node

I am trying to add two numbers in the form of linked List and return their result in a Linked List as given in https://leetcode.com/problems/add-two-numbers/ Question: You are given two non-empty ...
4
votes
1answer
93 views

Hashtable implementation in C for generic values

I am trying to implement a hashtable that supports character keys and can return any type of value contained in a struct as long as it contains as long as it contains ...
3
votes
2answers
74 views

c++14 move constructor and assignment in simple list

I’m moving from c98 to c++14 and I’m trying to figure out how to write move correctly. I just wrote the simplest list with no functionality, just testing the construction and copy behavior. I would ...
6
votes
2answers
1k views

Singly Linkedlist implementation in C++

I'm implementing a linkedlist in C++ with the essential functionalities. I would like to know what is good in this code and what is bad. In terms of everything (memory usage, functions ...
9
votes
2answers
119 views

Generic data structures in C

I'm new to C, and I thought a great way to learn would be to implement some generic data structures and algorithms. So far I've implemented a linked list and a dynamic array. Both are generic, the ...
2
votes
1answer
49 views

Singly-linked queue in PHP 7 #2

I have improved this post to the code below. As always, any critique is much appreciated! ...
2
votes
1answer
88 views

First attempt at making linkedlist in c

I started learning c and wanted to challenge myself by making a linked list. I am stil new to the concept of pointers and pointers to pointers, so there might be something in my code that I could have ...
2
votes
1answer
35 views

Adding elements of 2 linked list in reverse order

I solved a problem with JavaScript which has the following requirements: Two non-empty linked lists representing two non-negative integers. Digits stored in reverse order Each node contains a single ...
2
votes
0answers
12 views

Thread safe Shareable and Splittable Buffer with Safe Memory (Project)

Backstory This is a buffer I wrote for use in multiple personal projects. It is designed to handle pretty much any data in pretty much any way. In particular I intend to use it in such instances as ...
2
votes
1answer
289 views

Implementation of linked list in C++ using class

I created a linked list in C++ using class with few methods to provide interface for it. Methods are pushFront(), traverse() ...
1
vote
0answers
44 views

Merge k Sorted Lists

The task is taken from LeetCode Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: ...
4
votes
1answer
82 views

Linked List In Rust

I am still learning Rust and I think I have a long way to go. This question is from exercism.io. I am posting here to get some more reviews and suggestions to improve my code. Linked list aren't a ...
2
votes
0answers
46 views

Faster k-shortest path algorithm in Java

In the \$k\$-shortest path problem, we are searching for (at most) \$k\$ distinct, shortest paths connecting two given terminal nodes. You can see the previous version here. This implementation, ...
5
votes
1answer
275 views

C++ Implementation of Linked List

I have been trying to teach myself C++ recently and would like to have some general feedback and comments on how to improve my code so far. Furthermore, since I am more experienced with other (garbage-...
7
votes
4answers
10k views

Reversing a singly-linked List

Is this the best way to reverse a singly-linked list? Can it be done with two, or fewer pointers? Any other comments? ...
3
votes
1answer
77 views

Double Linked List

Note: Not a native English speaker. I have attempted to make a class similar to vectors in c++ (Though, I now know that it's just a (doubly) linked list). Just wanna know, how good or efficient my ...
5
votes
1answer
921 views

LRU Cache Implementation with HashTable and LinkedList

Problem Statement: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put. get(key) - Get the value (will always be ...
5
votes
2answers
74 views

Simple linked list with two iterators

As part of the practice, I created minimalist linked list named SimpleList which can be iterated in two different ways: one element after another or by every second ...
1
vote
2answers
67 views

Merging K Sorted Linked Lists

Specifically, how can I improve the time complexity of my algorithm (currently it is O(listLength * numberOfLists))? It only beats 5% of accepted LeetCode solutions,...
3
votes
0answers
68 views

Sorted LinkedList

A linked list is a data structure that has a beginning, and an end. The only way through the structure is to go to the "next step", like stepping stones. This linked list works the same way, but in ...
3
votes
1answer
29 views

Singly-linked queue in PHP 7

I am learning PHP 7 and decided to implement a simple FIFO singly-linked queue in it: ...
1
vote
0answers
47 views

Linked list delete a node with a particular value [closed]

I am trying to search a single linked list with a particular value and delete it. Only the first occurrence of the value. ...
2
votes
2answers
71 views

Leetcode: Flatten binary tree to linked list C#

https://leetcode.com/problems/flatten-binary-tree-to-linked-list/ Please comment on performance Given a binary tree, flatten it to a linked list in-place. For example, given the following ...
3
votes
2answers
417 views

Detecting a loop in a Linked list using a hashset

I was wondering if detecting a loop in a linked list using a HashSet is better than using two pointers? ...
3
votes
1answer
58 views

Adding two numbers represented as linked lists

I have some imminent interviews and want to sharpen my game before going into them. I'm running through some practice problems. This LeetCode challenge is to add two numbers represented as linked ...
14
votes
2answers
113k views

Stack implementation using linked list

This is a working stack implementation using a linked list. I'm just curious to know if this is a good way of doing it. Any suggestions are welcome. Can we keep track of the number of elements in ...
5
votes
2answers
134 views

First C program: records keyboard/mouse and simulates the recording afterwards

This is my first program ever made in C. Before that I programmed just a little bit in C++ (didn't touch OOP so I did only structural programming). This is my second "project" ever made, the first "...
1
vote
1answer
106 views

Process N lists simultaneously by doing permutations

I'm trying to see if someone can come up with a better solution for this algorithm. I have an input of three lists/queues and I have to group/sort the elements of ...
3
votes
1answer
49 views

(Ruby version) Rotate linked list to the right by k places

I saw this question (javascript - rotate linked list to the right by k places) the other day and I tried implementing it in Ruby in a totally different way. Here's the code (I also created a REPL if ...