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

A telephone book command line program in ANSI C

(See the next iteration.) Introduction I was in the mood for some C code and wrote this program for handling a personal telephone record book. One of the goals is strict portability; the code ...
3
votes
1answer
836 views

C++ implementation of a linked list

Can someone please review this code and provide comments? Please comment on error handling Is it right to do like this in method LinkedList::InsertFront()? ...
3
votes
1answer
4k views

Generic Stack (Array and Linked List) Implementation

I am working on brushing up my data-structures knowledge, and was hoping to have my code/thoughts reviewed. Thoughts on Generic Array Stack: Insertion/Pop are amortized to \$\mathcal{O}(1)\$. This ...
3
votes
3answers
111 views

Linked list implementation - follow-up

Follow-up to this question as recommended. Can this code be improved from an OOP paradigm perspective? ...
3
votes
1answer
947 views

Clone a linked list with a random pointer

I'm working on a problem to clone a linked list (each node has a regular next pointer), and each node also has a random pointer which could point to any node in the linked list. Each linked list node ...
2
votes
3answers
15k views

Linked list remove() and free()

How can I improve my remove function? Could someone also give me a solid explanation of the free() function? Here is my remove function: ...
2
votes
1answer
1k views

Extract Leaves of a Binary Tree in a Doubly Linked List

Given a Binary Tree, extract all leaves of it in a Doubly Linked List (DLL). Note that the DLL need to be created in-place. Assume that the node structure of DLL and Binary Tree is same, only the ...
2
votes
1answer
934 views

Python implementation as single linked list class `replace item` with item

I encountered this question as I am preparing for my code interview. I was implementing my linked list implementation. I would like to ask for the following implementation: Replace item with item ...
2
votes
1answer
5k views

Circular Linked List implementation in C++

I want to improve this code. ...
2
votes
2answers
1k views

Partition a singly linked list using Java

This is my attempted solution to exercise 2.4 in Cracking the Coding Interview. The problem statement is: Write code to partition a linked list around a value x such that all nodes less than x ...
1
vote
1answer
3k views

Sorted trie implementation in C

I wanted to store some dictionary data (key/value pairs of strings) in C, and decided to use a trie. I found what looks like a good implementation here, along with some nice notes. In this ...
1
vote
0answers
109 views

List interface implementation

After following the comment from greybeard, Below is the design for given first phase of implementation, Code directory structure, ...
1
vote
1answer
21k views

Doubly circular link list implementation

I am supposed to be creating a doubly circular linked list, but I am now have problems creating the actual linked list. Is there a problem with the classes? Also, for the assignment, the list is ...
0
votes
2answers
424 views

Merge sorting a singly-linked list in C

(See the next iteration.) I have this C implementation of the merge sort for sorting singly-linked lists: ...
13
votes
1answer
3k 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. ...
10
votes
1answer
288 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 <...
10
votes
2answers
3k 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. ...
7
votes
2answers
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 ...
7
votes
5answers
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 ...
7
votes
1answer
908 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 ...
6
votes
1answer
344 views

(Codewars) Linked Lists-Sorted Insert

Kata: https://www.codewars.com/kata/linked-lists-sorted-insert Description Write a SortedInsert() function which inserts a node into the correct location of a pre-sorted linked list which is ...
6
votes
4answers
637 views

Generic circular doubly linked list

Edit: New version improved with the answers and comments received here: Generic circular doubly-linked list v2 I have written a linked list library that I can use whenever I need a linked list, so ...
6
votes
3answers
799 views

Generic single linked list

I am a mathematician attempting to become proficient with C++. At the moment I am learning about data structures. I am tried writing a single linked list from scratch with some help from online ...
6
votes
2answers
3k views

Operating sublists efficiently

In my Java program, I need to operate on the sublists a of ArrayList or LinkedList often, like removing a sublist, comparing two ...
5
votes
2answers
455 views

Singly linked list

The struct and the prototypes of the functions were given in the question. I am unfortunately aware that this is more C code and less C++ code. I am looking to ...
5
votes
1answer
35 views

Double LinkedList Deep Copy in Kotlin with Generics and Thread Safety

Goal Return a deep copy of a double LinkedList. Each node also contains an additional random pointer, potentially to any node or null. Code to start ...
5
votes
1answer
458 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 ...
5
votes
1answer
111 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
2answers
344 views

C++ linked list iterator implementation

I'm a first year computer engineering student and would appreciate feedback on some code. I've created a linked-list with an iterator to be able to range for loops like: ...
5
votes
2answers
3k views

Adding two BigInts using linked lists in C

While trying to learn more about linked lists, I thought I should try the exercise of reading two BigInts from an input file and then adding them up. My strategy was to store the two numbers in two ...
5
votes
2answers
317 views

Stack implemented using a single linked list

I am studying data structures and I have implemented a stack using a linked list. stack.h ...
5
votes
2answers
91 views

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

(See the previous iteration.) What does this program do? This program gives you a command line interface for managing your personal telephone book. The program supports three actions: Adding a ...
5
votes
1answer
232 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 ...
4
votes
2answers
86 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 ...
4
votes
1answer
52 views

Doubly linked list in Cython

I am implementing a BVH (Bounding volume hierarchy) in Cython and thought of using a doubly linked list to hold reference of the volumes that still need to be split and push new volumes at one end ...
4
votes
1answer
562 views

Template double ended queue (deque) implementation using dynamic allocation C++

I have written my own deque class to get a better grasp of C++ pointers and memory management. The following code is part of a larger 2D isometric game I am developing. It compiles and runs fine using ...
4
votes
1answer
157 views

C++ linked list

The following code seems to work ok to remove a node from a linked list: ...
3
votes
3answers
128 views

Linked List Interview Code methods, runtime, and edge cases refactored

In my previous post I had a number of steps given to me from the accepted answer on how I can write more production ready code. In this post I want this code to be reviewed as near production code I'd ...
3
votes
3answers
208 views

Simple imperative linked list

I've decided to learn a bit of C++, and so I've started with a simple linked list. There's no input to the program and should always output hlo. This is as in ...
3
votes
1answer
40k views

Deleting a linked list node

This is a classic linked list problem. Deleting a node from linked list given the data to be deleted. Inserting a node in a sorted linked list. I saw various versions of this and here is my version. ...
3
votes
1answer
100 views

Convert a Binary Tree to Doubly Linked List

Challenge Link on geeksforgeeks: Binary Tree to DLL Given a Binary Tree (BT), convert it to a Doubly Linked List(DLL) In-Place. The left and right pointers in nodes are to be used as previous ...
3
votes
2answers
104 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 ...
3
votes
1answer
87 views

Creating a generic single linked list, follow up

This is a thread I started from here. I organized my code to make it more organized. Everything works well, but I have not made all the changes from the last link (namely namespace since I am exactly ...
3
votes
1answer
64 views

Implement LinkedList class in python

I am currently study the basic data structure and trying to implement everything as I go. can anyone give me some feedback about class LinkedList how to make the code more elegant. any review are ...
3
votes
2answers
665 views

Merge sorting a singly-linked list in Java

I have this nifty merge sort implementation for sorting singly-linked lists. Its running time is \$\Theta(n \log n)\$, yet it uses only \$\Theta(\log n)\$ space (the stack). See what I have below. ...
3
votes
2answers
225 views

Singly linked list class

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

Data Structures in C (Single Linked List)

NOTE: Added a follow-up question with the reviewed code I am trying to get back to basics with C, so I am doing some data structures in it. The following is my implementation of a Single Linked List ...
3
votes
1answer
35 views

Singly-linked queue in PHP 7

I am learning PHP 7 and decided to implement a simple FIFO singly-linked queue in it: ...
3
votes
1answer
63 views

(Ruby version) Rotate linked list to the right by k places

I saw this question (javascript - rotate linked list to the right by k places) the other day and I tried implementing it in Ruby in a totally different way. Here's the code (I also created a REPL if ...
3
votes
3answers
197 views

Rotate a linked list to the right by k places

The task Given a linked list and a positive integer k, rotate the list to the right by k places. For example, given the linked list 7 -> 7 -> 3 -> 5 and k = 2, it should become 3 -> 5 -> 7 ...