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
32 views
0
votes
2answers
74 views
Leetcode: Merging 2 sorted lists
https://leetcode.com/problems/merge-two-sorted-lists/
Merge two sorted linked lists and return it as a new list.
The new list should be made by splicing together the nodes of the first two lists.
...
0
votes
1answer
27 views
Simple text-based inventory manipulator
I was bored so I crapped out a simple game that responds to commands and manipulates an inventory.
I am interested in other possible ways to handle the inventory,
and I think I went overboard with ...
4
votes
3answers
79 views
Linked List written in C
I have been learning data structures and dynamic memory allocation in C. As a learning experience, I have written this linked list implementation. I really appreciate the feedback I've received on the ...
9
votes
1answer
440 views
Simple LinkedList
I guess this has been made a couple of times by now, but i wanted to take my chance on creating a simple generic linked list in c#.
What do you think ?
This is the main class.
...
5
votes
2answers
121 views
Stack implementation in C++ using linked list
I am learning C++ and I made a simple stack class using a (reversed) linked-list to test my knowledge.
Are there any problems with the following code, or any suggestions to improve it?
I want to ...
1
vote
1answer
74 views
3
votes
2answers
113 views
1
vote
1answer
119 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() ...
3
votes
0answers
51 views
Linked-list natural merge sort in Python
I implemented the linked-list natural merge sort in Python, and I refered to this awesome if not poetic gist and this implementation in Go. Here is my code:
...
1
vote
1answer
36 views
3
votes
1answer
46 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
71 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
38 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
56 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 ...
2
votes
3answers
79 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
61 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 ...
5
votes
3answers
75 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
45 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
102 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
2answers
45 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
125 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
54 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
65 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
48 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
52 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
97 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
90 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
99 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
124 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
30 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
139 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
84 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
69 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
78 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
113 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
104 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
145 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
127 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
77 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
118 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
16 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
57 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
93 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
73 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
174 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
70 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
112 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
275 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
83 views
Linked List using templates and smart pointers
I have an implementation of Linked List with push, pop, ...