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.

2
votes
1answer
73 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 ...
0
votes
0answers
18 views

Inserting nodes to the end of a linked list by function [on hold]

I am trying to insert nodes to the end of a linked list by function. This is the insertNode function: ...
-1
votes
0answers
26 views

Linked list in the linked list c++ [on hold]

Example:: Receipt1: Name:Customer 1 Order::: Index:1(Name:Frame0001, Quantity:1)+ Index:1(Name:Frame0001, Quantity:2) Receipt2: Name:Customer 2 Order::: Index:1(Name:Frame0001, Quantity:15) Problem ...
1
vote
1answer
63 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
36 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
65 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 ...
0
votes
0answers
15 views

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

To start with, I know that this question has been answered in Java and C++, but I was wondering if it were right to answer it in JS. And in the event that it is, then whether this solution can be ...
1
vote
2answers
12 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
47 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
87 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
41 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
82 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
63 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
97 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 ...
2
votes
1answer
97 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
62 views

Linked List using templates and smart pointers

I have an implementation of Linked List with push, pop, ...
4
votes
2answers
301 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
162 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
55 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 ...
2
votes
1answer
202 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
145 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
81 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
128 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
48 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
67 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
51 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
53 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
594 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
45 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 ...
7
votes
5answers
398 views

Add Two Numbers given in Reverse Order from a Linked List

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

Generic Single Linked List with smart pointers follow up part 3

Okay, this will most likely be the last post I make for Singe Linked List unless significant revision is needed. This post following from here. Shout out to @hoffmale for showing me the ways of the ...
3
votes
2answers
64 views

A Stack Implementation In C

I've written a very simple linked list based stack implementation and was wondering if this is the standard way to do it in C. ...
9
votes
2answers
186 views

Modern C++ singly linked list

This is a rather minimal (though fully functional) implementation of a singly linked list. It supports \$\mathcal{O}(1)\$ front insertion and deletions, as well as \$\mathcal{O}(1)\$ random insertions ...
2
votes
2answers
65 views

Generic Single Linked List with smart pointers follow up part 2

This is probably the last time I will post this data structure that I have been working on. I have added in an iterator and const_iterator class (although I do not use them probably where I should be)....
5
votes
2answers
62 views

LinkedList class implementation in Python

I was solving this problem for implementing LinkedList and ListNode classes, and Insert and <...
2
votes
1answer
111 views

Reverse a linked list

I was given 15 minutes to write the code to reverse a singly-linked list. What do you think of the code style here? ...
5
votes
2answers
706 views

Remove the first value for a doubly linked list

You need to remove the first element which contains a given value from a doubly linked list. I created two solutions since I find the edge case of removing the first element to be problematic. So I ...
2
votes
4answers
125 views

Generic Single Linked List Using Smart Pointers Follow up

I am extending this post following from here. I made some of the changes that I could make in the previous post. Although, I have not been successful in creating iterators for my class. The reason ...
1
vote
3answers
77 views

Stack implemented with linked list

I have looked at some previous posts and changed my code accordingly. Do you have some suggestions about my current code? Here are my specific questions: What should ...
5
votes
4answers
144 views

Generic Single 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 ...
4
votes
2answers
213 views

Doubly linked list std::unique_ptr template class implementation

Inspired by the talk of Herb Sutter in CppCon2016, I decided to make a doubly linked list using templates, smart pointers, and raw pointers (for back-pointers, having a cycle of ...
4
votes
2answers
133 views

Thread-safe cache using a linked list

Are the final templated functions allocate and deallocate thread safe? The Cache object is a ...
3
votes
1answer
74 views

C++ linkedlist with static next/prev pointers

I did huge review of linkedlist implementations and all of them include separate new call fornode part for entry, which has <...
2
votes
1answer
178 views

Insert and Delete at Head and Tail of Linked List in constant time

I am trying to write a Linked List implementation that can insert and delete at either head or tail in constant time. I think I have it working, but I was curious what improvements I could make to ...
4
votes
1answer
68 views

JavaScript circular linked list compatriot game

I found this question in O'Reilly Data Structure and Algorithm in Javascript: According to legend, the first-century Jewish historian Flavius Josephus was about to be captured along with a band ...
0
votes
2answers
35 views

Delete K nodes in a linked list having their data less than the next node's

The question is from here. Given two numbers N and K where N is the number of nodes and K is the number of nodes to be deleted, delete K nodes whose data is less than their next node's data. If no ...
3
votes
2answers
100 views

Generic Stack Data Structure Using Linked Lists Follow Up

I made a post that follows from this here. I made most of changes that I could understand from the following link, and here is now an update to that original post. I just want to see if there is any ...
1
vote
1answer
56 views

Fixed size double linked list in Scala

I have written a double linked list in Scala. The list should be fixed in size and items are always added to the head. if the list reaches max size then the tail is dropped. This is my code. I want ...
3
votes
2answers
77 views

Generic Double Linked List Follow up

This is a continuation from the previous post found here. I made most of the changes that was suggested. I just want to see if there are any additional changes I should make to my code. Here is my ...
4
votes
3answers
132 views

Sort a linked-list with only three distinct values

I am trying to solve this problem. The problem is to sort a linked list containing only 0s, 1s and 2s by changing their links. Sort a linked list of 0s, 1s and 2s by changing links Given a linked ...