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
1
vote
1answer
42 views

Swapping alternate nodes of linkedlist

...
4
votes
1answer
1k views

Leetcode MaxStack in Python

My solution to Leetcode MaxStack in python in Python. I have two solution one is using linked-list and another one is using list. Design a max stack that supports push, pop, top, peekMax and popMax. <...
0
votes
2answers
119 views

Doubly linked list C++ [closed]

To become more familiar with templates I attempted a doubly linked list implementation in C++. Is this a valid use for a template? ...
1
vote
2answers
582 views

Pairwise swap elements of a given linked list by changing links

GeeksForGeeks challenge: Given a singly linked list, write a function to swap nodes pairwise. For example : if the linked list is 1->2->3->4->5->6->7 then the function should change it ...
3
votes
1answer
385 views

Rotate the sub-list of a linked list from position M to N to the right by K places

Given a linked list and two positions m and n. The task is to rotate the sub-list from position ...
4
votes
3answers
738 views

Stable-sorting all even numbers before odd numbers in a linked list

Given a Linked List of integers, write a function to modify the linked list such that all even numbers appear before all the odd numbers in the modified linked list. Also, keep the order of even ...
1
vote
1answer
143 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 ...
4
votes
3answers
96 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
208 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
121 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 ...
1
vote
2answers
77 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,...
6
votes
3answers
274 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
71 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
238 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
91 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
787 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
431 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
167 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. ...
6
votes
1answer
937 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
2answers
518 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
147 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
406 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 ...
4
votes
1answer
503 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 ...
5
votes
1answer
150 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 ...
6
votes
1answer
250 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
321 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
374 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
5k 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 ...
2
votes
1answer
343 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 ...
5
votes
1answer
373 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
414 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
82 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
172 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
115 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
398 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 ...
4
votes
1answer
2k 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 ...
4
votes
3answers
87 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
380 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
1k 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
212 views

Linked List using templates and smart pointers

I have an implementation of Linked List with push, pop, ...
4
votes
2answers
1k 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
196 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
106 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 ...
7
votes
2answers
3k 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
1k 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
547 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
549 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
1k 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
2k 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
116 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
3 4
5
6 7
21