Skip to main content
Share Your Experience: Take the 2024 Developer Survey

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
13 votes
1 answer
4k views

My first implementation of a linked list in C++

This is my very first implementation of a full-fledged ADT, which could potentially be use-ready. Now, I'm still learning, therefore I would like to ask you what I can do to further improve the ...
ImQ009's user avatar
  • 133
9 votes
3 answers
13k views

Linked list implemented as classes, not imperative code

As an update to previous code I've submitted: Improvements this time are mainly having everything moved to a class, before I plough on and add more functionality (I've come back to C++ after a few ...
Tom Kealy's user avatar
  • 505
7 votes
1 answer
2k views

Swap items of a linked list in pairs

Here is the source of the question: GitHub Given a singly linked list, swap the list items in pairs (reconnect the pointers, not simply swap the values). For example: Before: A->B->C->D ...
Maksim Dmitriev's user avatar
3 votes
1 answer
232 views

Singly linked list optimized for search & insert in O(1)

I have tried to implement my singly linked list to be optimal in the sense that when inserting I don't have to search for the tail and then chain the new node to it, I just keep track of the tail and ...
V_head's user avatar
  • 525
30 votes
2 answers
58k views

Custom iterator for a linked list class

I have made a LinkedList class. This is a singly-linked-list and I want to make a forward_iterator for this class without using ...
Rohith R's user avatar
  • 403
13 votes
4 answers
4k views

Linked list in C++

Could someone review my linked list code? Specificially, is the design to separate Node and actions to create linked list appropriate? ...
ersran9's user avatar
  • 233
3 votes
1 answer
172 views

Swap items of a linked list in pairs - revision 2

The first revision is available here and the code is available on GitHub. I modified the method reversePairs and added mSize to ...
Maksim Dmitriev's user avatar
3 votes
2 answers
367 views

singly linked list optimally defined over operations in C?

I have implemented my singly linked list in C and I tried to do it with the most efficient code as possible. Is there any place for improvement? This post is the second version. First version of this ...
V_head's user avatar
  • 525
2 votes
1 answer
83 views

Swap items of a linked list in pairs - revision 3

Here is the source of the question. Revision 1. Revision 2. When I started the second round of code review, I wanted to make sure that I had included all the possible input types. However, I ...
Maksim Dmitriev's user avatar
2 votes
2 answers
228 views

singly linked list optimally defined over 17 operations in C [2]?

Previous versions of this question First Version Second Version Changes I added these operations: Pop_back Pop_front You are not allowed to insert_sll at the ...
V_head's user avatar
  • 525
20 votes
3 answers
4k views

Reversing k-sized sequences in a linked-list

Here is my solution to this problem; please be brutally honest/strict, if I would have written this code, in a 45 minute interview, what would you think? (I am aiming for Google,Facebook). Here is ...
bazang's user avatar
  • 2,236
18 votes
5 answers
5k views

Self-made Linked List

I was tasked by my teacher with making a linked list by myself, so I could understand the concept better. Here is the MyLinkedList class: ...
Attila Herbert's user avatar
10 votes
2 answers
4k views

Check if an element is present within a linked list

I am given a task to ask for a number and then check if it is present within a linked list or not. ...
Latika Agarwal's user avatar
8 votes
4 answers
26k views

Doubly linked list in C++

Please, review the code: ...
Medicine's user avatar
  • 443
7 votes
4 answers
538 views

General advice on a practice linked_list for C++ classes/templates

Introduction I'm learning C++ (Coming from Haskell, C, and Assembly - and other languages sparsely) and this was my practice with classes and templates. It's a linked list that you can call in this ...
GRAYgoose124's user avatar
7 votes
5 answers
2k 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 ...
greg's user avatar
  • 1,017
6 votes
2 answers
1k views

Creating a Generic Single Linked List

This follows from a post I made here. I made changes according to the answer I accepted in the following link. I tried to make all the changes necessary that I could. I just want to see if there are ...
Snorrlaxxx's user avatar
6 votes
2 answers
20k views

Phone Book Program in C++

I am starting out a school project to build a phone book program in C++. It stores contacts in a linked list. This currently does not have all the validations I would like to implement, and is all in ...
Frank Doe's user avatar
  • 259
4 votes
2 answers
275 views

Linked list implementation along with unit test - Round 2

Here is the link to the next round of code review: Linked list implementation along with unit test [Round 3] Here's the link to the previous code review: Linked list implementation along with unit ...
feature_creep's user avatar
3 votes
2 answers
130 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 ...
Snorrlaxxx's user avatar
3 votes
1 answer
103 views

Data Structures in C (Single Linked List) - Follow-up

This is a follow-up from my previous question! I cleaned up the code and added all the notes from the answers. I have also updated the code on github LinkedList.h ...
AntonioCS's user avatar
  • 536
3 votes
2 answers
316 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 ...
t3chb0t's user avatar
  • 44.3k
2 votes
1 answer
216 views

Faster, indexed, heuristic doubly-linked list data structure in Java: implementation

I have this doubly-linked list data structure that runs all the single-element operations in \$\Theta(\sqrt{n})\$ time (refer to this post and this repository). (See this for benchmarks.) (See this ...
coderodde's user avatar
  • 28.4k
2 votes
1 answer
630 views

Tic-Tac-Toe with changeable board size (Part 2)

Part 1: Tic-Tac-Toe with changeable board size (Part 1) I just revisited all my previous questions and saw that I hadn't updated my Tic-Tac-Toe code. So, I improvised my code as per @Austin Hastings ...
Sriv's user avatar
  • 2,740
2 votes
1 answer
4k views

Delete nodes in linkedlist whose next node is greater

Given a singly linked list, remove all the nodes which have a greater value on right side. Examples: a) The list 12->15->10->11->5->6->2->3->NULL should be changed to 15->11->6->3->NULL. ...
JavaDeveloper's user avatar
1 vote
1 answer
68 views

A telephone book command line program in ANSI C - follow-up

(See the next iteration.) This question is a slight improvement over A telephone book command line program in ANSI C I have incorporated almost all points stated by Toby Speight. Now I have this: ...
coderodde's user avatar
  • 28.4k
1 vote
1 answer
97 views

Swap items of a linked list in pairs - revision 4

Here is the source of the question. The solution on GitHub. Revision 1. Revision 2. Revision 3. @200_success' suggestions from revision 3: The iterator's ...
Maksim Dmitriev's user avatar
0 votes
3 answers
2k views

Given a two dimensional linked list, create a flattened sorted list

A node has a next and down pointer. Merge the linked-list such that end result is sorted. Here we have a top level linked-list, followed by a down-list. If { 10 : {20, 30} , 35 { 40, 50 } } is the ...
JavaDeveloper's user avatar
34 votes
3 answers
90k views

LinkedList with Node implementation

Below is my implementation of templated Node and LinkedList classes. I would really appreciate it if someone would give me ...
Yechiel Labunskiy's user avatar
14 votes
1 answer
4k views

Linux NASM assembly linked list implementation

Inspired by all of the lovely linked lists lately, I decided to implement one in assembly language. This code maintains two linked lists - one is a free store and the other is the active linked list. ...
Edward's user avatar
  • 66.4k
14 votes
6 answers
16k views

In-place reversal of a singly linked list

As suggested in The 2nd Monitor, I'd like a review of this in-place reversal of a singly linked-list: ...
Jerry Coffin's user avatar
  • 33.6k
13 votes
3 answers
970 views

Reversing a linked list

I implemented reversing a linked list in iterative way, just by knowing we need 3 pointers and I have never seen a code before, when I coded. I ran this code and tested it, it works fine. Even for ...
howtechstuffworks's user avatar
13 votes
1 answer
6k views

Simple trie implementation in JavaScript

After experimenting with a sorted trie implementation in C, I felt that I understood tries pretty well, but was having trouble explaining how they work. Since the C code was based on existing code, I ...
Dagg's user avatar
  • 4,531
13 votes
2 answers
30k views

Self-made linked list iterator

I recently made a linked list for myself, the code of which was posted here, if anyone would be interested. Now, as the next task, I had to make an Iterator for my ...
Attila Herbert's user avatar
12 votes
4 answers
3k views

Singly Linked list implementation in C++

How can I improve this code Please tell proper indentation and usage of camel-case. ...
Dhruv Sehgal's user avatar
11 votes
3 answers
15k views

C++ Stack using template

I'm learning C++, so I wrote a stack with the help of templates. I'm wondering if there is anything I can improve or if I did something vastly wrong. Stack.h ...
Caresi's user avatar
  • 113
11 votes
4 answers
1k views

Type-generic queue implementation using singly linked lists

Simple lightweight queue implementation using data size registration and singly linked lists as the underlying type Update #2 ...
Mode77's user avatar
  • 663
11 votes
3 answers
10k views

Linked list implementation correctness

I've started learning C++ and I wanted to ask you to take a look at my linked list implementation and give comments what's wrong with. It compiles and runs fine, but I am curious about const ...
Michael Naumov's user avatar
11 votes
3 answers
9k views

Doubly-Linked Circular Linked List

I'm a C++ programmer learning Java in preparation for an OOP class this fall. That being said, Java is fairly new to me so I'd love to hear feedback on how to improve this code. A few notes: Code ...
user avatar
10 votes
1 answer
305 views

Tweets per second, using linked list

This is a TalentBuddy Challenge Your task is to write a function that prints to the standard output (stdout) the highest number of tweets recorded between each second in the array and the past <...
BenVlodgi's user avatar
  • 4,278
9 votes
2 answers
292 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: <...
Matan Cohen's user avatar
9 votes
2 answers
255 views

Linked List reversal

Recursive version. The only interesting function: ...
Martin York's user avatar
  • 95.2k
8 votes
2 answers
2k views

Java Singly Linked List Implementation

I've implemented a singly linked list in Java as a practice exercise and would appreciate a review. LinkedList.java ...
j.castillo's user avatar
8 votes
1 answer
4k views

Linked list implementation along with unit test

I've already made all the changes suggested here. Here is the link for round 2: Linked list implementation along with unit test [Round 2] I want to see how other people think of my code, so here it ...
feature_creep's user avatar
8 votes
5 answers
1k views

Singly Linked List Implementation in C

I'm preparing for an interview soon, and I've written the following linked list implementation from scratch. This is all self-taught, and I'm still working on my C. I feel that the implementation is ...
Impossibility's user avatar
7 votes
1 answer
351 views

Generic Double Linked List

I am a mathematician attempting to become proficient with C++. At the moment I am learning about data structures. I am trying to write a double linked list now from scratch with some help from online ...
Snorrlaxxx's user avatar
7 votes
2 answers
3k views

Building a simple singly-linked list in C++11

The implementation below works, but I'm wondering if there's a modern C++ alternative. For example: Should I replace the raw new with a braced initializer? Should ...
nachocab's user avatar
  • 261
6 votes
4 answers
967 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 ...
Snorrlaxxx's user avatar
6 votes
2 answers
155 views

Generic circular doubly-linked list v2

I've improved, with help of the answers and comments, the linked list that I posted yesterday. It's been through a lot of changes, and is much more useful and safe now. I documented the linked list ...
alx - recommends codidact's user avatar
6 votes
3 answers
823 views

Implementation of the linked list data structure in C++

How is this designed so far? ...
user avatar