Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
1answer
47 views

Generic Linked List (header-only and non-intrusive)

Although I should know better, I wrote my own linked list implementation in C. My goal was to make it a true generic collection, with no need to modify the structure being listed. I only ...
-1
votes
0answers
10 views

Data structure method in java [closed]

My question is : How can I connect the first node, last node and new node when I add item at the beginning or at any position? Assume that there is a interface called StudentInterface has three ...
-4
votes
0answers
21 views

Connecting node in a linked list [closed]

My question is : How can I connect the first node, last node and new node when I add item at the beginning or at any position? Thanks ...
-2
votes
0answers
13 views

Array of Linked Lists into one list in C [closed]

I am trying to get all integer in an array of linked lists to form into one linked list. I am getting run time error and I think its from this function stitchBuckets. Am I suppose to use double ...
5
votes
3answers
68 views

Closed linked-list which uses sentinels to avoid passing itself

This is a typical C implementation of a (doubly) linked-list. I want to avoid passing the element and the list itself to functions which operate on and possibly ...
1
vote
1answer
41 views

My own expandable list in Python

I have written my own expendable list in Java. LinkedList in Java Now I tried to write that thing in Python. Did I have used the elements of the python language properly? ...
2
votes
2answers
98 views

My own expandable list

I wondered how an expandable list could be implemented. My first thought: You could create a class that has an array and you can create a new array each time the user wants to append an element and ...
0
votes
1answer
29 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,...
5
votes
3answers
119 views

Singly-linked list data structure implementation

This code seems to work correctly. I would appreciate any comments on how to improve the code, e.g. readability, algorithms, const-correctness, memory, anything else I am forgetting? Also, for the ...
-2
votes
1answer
49 views

Build up two linked list, then build up a 3rd link list with nodes of duplicate data from both [closed]

A friend of mines needed some help. He wanted to build up two linked list and then compared them to see if they had the same data values. Finally a 3rd link list would contain the nodes with ...
3
votes
2answers
64 views

Singly linked list class

I have created this program about using a singly linked list class that implements several functions: Add, Display and ...
0
votes
2answers
38 views

Singly Linked List Implementation (With Nodes)

This code was recommended to me by my dear friend Jon after I wrote an implementation using arrays. With his help, I managed to create a Singly linked List similar to std::vector using Nodes. ...
3
votes
0answers
42 views

Linked list with hand-over-hand locking

Follow-up to this question: after reading the comments, I decided to redesign my linked list to have a cursor that only contains one node and implement the interface similar to the one of forward_list ...
3
votes
2answers
87 views

Remove value from linked list if it is equal to a parameter

Problem: Given a singly linked list of integers l and an integer k, remove all elements from list l that have a value equal to k. My solution works, but I suspect it's not smart and optimized ...
1
vote
2answers
78 views

HashMap implementation, is this good enough for interviews?

After understanding HashMaps, I decided to implement my own using 3 classes HashMap, LinkedList, and Node. I knew how to implement LinkedList from before. Can you please give me feedback on this. ...
5
votes
1answer
91 views

Specialized ConcurrentLinkedList

I need a concurrent data structure with the following properties: Low overhead for enumeration Insert only at end. Removal from any point. Enumeration should be safe with concurrent writing ...
0
votes
1answer
66 views

Josephus Problem with cyclic iterator

Given the Josephus Problem. Josephus Problem N people (numbered 1 to N) are standing in a circle. Person 1 kills Person 2 with a sword and gives it to Person 3. Person 3 kills Person 4 and ...
1
vote
0answers
29 views

C Generic Sorted Doubly-Linked List

I just finished this big project. Its is called SortedList and it is implemented using a Doubly-Linked List. It data is of type ...
2
votes
2answers
90 views

Doubly linked list in C

While I'm training to get better at C, I tried my hand at making a doubly linked list implementation. linkedlist.h ...
3
votes
1answer
67 views

Merge two sorted lists in Rust

I wrote the following code to merge two sorted lists. Is there a way I can improve it? Possible ideas (not sure how to implement them): Remove code duplication (setting the returning list node and ...
4
votes
1answer
67 views

Implementation of Singly Linked List

I'm a data scientist attempting to build stronger CS fundamentals, particularly in Data Structures & Algorithms. Below is my attempt at implementing a Singly Linked List. Looking for advice ...
5
votes
1answer
63 views

Implementing a doubly linked list with smart pointers

I've been learning Rust for the past few days and I just passed the "Smart Pointers" chapter. To check what I've learned I've decided to implement a doubly linked list. My question is, is this ...
5
votes
1answer
96 views

Linked List implementation in Python

I'm a data scientist attempting to build stronger CS fundamentals, particularly in Data Structures & Algorithms. Below is my attempt at implementing a Singly Linked List. Looking for advice ...
2
votes
1answer
67 views

Leetcode #146. LRUCache solution in Java (Doubly Linked List + HashMap)

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 ...
2
votes
1answer
107 views

Doubly linked list using C++ and templates

Working doubly linked list using C++ and templates, I tried to make it by myself. I tried to use head and tail as buffers and make a simple implementation. Please help me understand what I have done ...
1
vote
1answer
118 views

Stack using Linked List in Swift

I made this implementation of a stack in Swift that stores its elements as a linked list. It seems to work perfectly well, but I’m wondering how I can improve it to follow the best practices of the ...
4
votes
1answer
53 views

Implementing a queue using a linked-list

In my intro CS class we're reviewing data structures. I'm currently working on implementing a queue using a linked list (FIFO) in C. I'd appreciate a review of the implementation as well as of my ...
2
votes
3answers
76 views

Implementing a stack using a linked-list

In my intro CS class we're reviewing data structures. I'm currently working on implementing a stack using a linked list (LIFO) in C. I'd appreciate a review of the implementation as well as of my ...
1
vote
2answers
14 views

Implement an algorithm to find the Kth to last element of a singly linked string

I wrote this algorithm to find the Kth element of a singly linked list and I would like your feedback because I want to know if there is a better version. In my eyes, this is the most optimized way ...
1
vote
1answer
49 views

DynamicList/LinkedList Queue Implementation

here is my LinkedList Queue Implementation , seems like its almost like the linkedlist implementation with little differences mainly in the poll() method, i think that the offer() method is same like ...
2
votes
2answers
90 views

LinkedList Stack Implementation

I'm new to the programming and I want to ask a question about my linkedlist stack implementation if it's correct and if it meets the requirements of the linkedlist stack implementation. If there is ...
1
vote
1answer
54 views

Doubly-linked list program with delete functions

I'm starting to learn Java (started with C++), and still getting to get used to the syntax and whatnot. For practice, I made a doubly-linked list program. Is there any way this could be improved at ...
3
votes
1answer
107 views

Doubly linked list in Rust

I have just started learning Rust, and in order to try to get the hang of references, ownership and mutability, I have attempted to make a doubly linked list. It now compiles, and the ...
2
votes
3answers
67 views

Stacks using Linked Lists in C

I tried to implement a stack using Linked Lists. How could I make it more efficient? Any other suggestions will be greatly appreciated. I am a beginner C programmer. Any other tips to clean up my ...
5
votes
2answers
102 views

Object pool and sorted linked list in C

Update: Have implemented some of the suggestions: See GitHub: https://github.com/BostonBrooks/MathsGame/tree/master/Object_Pools_Demo I am implementing a game engine where I have a sorted list of ...
3
votes
1answer
155 views

Find the kth-to-last element of a singly linked list

I wrote this code for finding the \$k\$th-to-last element in a singly linked list. ...
2
votes
1answer
80 views

Linked List using templates and smart pointers

I have an implementation of Linked List with push, pop, ...
4
votes
2answers
330 views

C++ linked list inheritance hierarchy

I'm about to post quite a bit of code. Hopefully, someone is willing to put some time into reviewing it all. I know linked lists have been done a lot on here, but I wanted to improve the basic C++ ...
5
votes
2answers
167 views

Deficient Numbers

I have found the following interesting challenge on the web: Deficient Numbers A number is considered deficient if the sum of its factors is less than twice that number. For example: 10 is a ...
3
votes
2answers
59 views

Return Kth to Last: Implement an algorithm to find the kth to last element of a singly linked list

Implement an algorithm to find the kth to last element of a singly linked list. Any comments or feedback regarding this? I came up with another algorithm that uses ...
3
votes
1answer
603 views

Doubly Linked List in Python

I implemented a doubly linked list in Python. Please tell me what I can do to improve performance, what methods I should add, etc. I gave it the best Big O time perfomance/complexity I could. So, here ...
5
votes
1answer
187 views

Singly Linked List in Python

A school student here. Hope you are having a nice day. So, I implemented a Singly Linked List in Python and of course also a Node. I tried to make it have the best Big O time complexity I could. Here ...
5
votes
1answer
109 views

“Add two numbers given in reverse order from a linked list”

Original Question Problem Description 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 contain a ...
4
votes
2answers
161 views

Double Linked List Using Smart Pointers

I have decided to rewrite what I did here, following the suggestions to use smart pointers. I will rewrite the other data structures as well using smart pointers where appropriate. I just want to see ...
0
votes
1answer
58 views

A simple linked list of arrays in Java

Introduction This simple data structure combines ArrayList with LinkedList. In other words, it is a linked list of arrays: ...
0
votes
2answers
150 views

LRU Cache in constant time

I would like to ask for code review for my LRU Cache implementation from leetcode. Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following ...
1
vote
0answers
56 views

Speeding up a linked list by using fingers in Java

The idea here is to keep a small number of "fingers" that point to linked list nodes. Now, when, say, the client programmer asks for a node in the list, a closest finger is chosen and is shifted to ...
1
vote
0answers
56 views

selecting 5 best players out of 2 team

Let us assume that we need to develop an application which can select best 11 players to score maximum points. The application will select the best players after completion of a match. The rules are ...
6
votes
3answers
605 views

Double Linked-List Implementation

I implemented a Double linked list in c++ to practice. I reviewed the code myself and I would like others perspective about the improvements that could be made. I have also noticed that I don't take ...
-2
votes
1answer
48 views

Deleting a node in Linked list [closed]

For deleting a node in linked list I used 3 steps: 1)Finding the previous node of the node to be deleted. 2)Changing the next of the previous node.(to know what is next see my code it's fully ...