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
3
votes
1answer
756 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()? ...
2
votes
1answer
3k 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 ...
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
555 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
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 ...
2
votes
1answer
4k views

Circular Linked List implementation in C++

I want to improve this code. ...
2
votes
3answers
13k 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: ...
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
1answer
20k 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 ...
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, ...
0
votes
2answers
409 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
287 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
2k 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
1answer
177 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 ...
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 ...
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 ...
6
votes
1answer
289 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
3answers
698 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
2k 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 ...
5
votes
2answers
111 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
1answer
326 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
84 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
161 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 ...
5
votes
2answers
2k 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
83 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
2answers
446 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
2answers
315 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 ...
4
votes
1answer
511 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
141 views

C++ linked list

The following code seems to work ok to remove a node from a linked list: ...
4
votes
1answer
38 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 ...
3
votes
1answer
84 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
2answers
7k views

Insert a node at a specific position in a Linked List

This code is built to insert a Node into a specific position of a linked-list. It passes all the test cases for the interview, but I was wondering about the coding ...
3
votes
1answer
50 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
1answer
29 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
1k views

Stack - Implemented as Singly Linked List

Note: I do know that Python libraries provide a Linked List and Stack. This implementation has been done to practice ...
3
votes
2answers
197 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
1answer
39k 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
3answers
85 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 ...
3
votes
3answers
210 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
3answers
118 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
2answers
251 views

SPOJ Class Leader using circular linked list

I have solved a spoj question CLASS LEADER. For each test case there are n students and a paper will be given to student m and now the game starts, the student m will pass the paper by o positions ...
3
votes
1answer
58 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
3answers
235 views

Is SList class an ADT?

As per the definition given in lecture, ADT is, With reference to this definition, I would like to call SList class an ADT following 6 invariants: Multiple users ...
3
votes
2answers
90 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
3answers
194 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
3answers
361 views

Merge sorting a singly-linked list in C - follow-up

(See the initial iteration.) Continuing from Merge sorting a singly-linked list in C, I have incorporated the points made by @vnp. Now it looks like this: ...
3
votes
2answers
653 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. ...
2
votes
0answers
50 views

Faster k-shortest path algorithm in Java

In the \$k\$-shortest path problem, we are searching for (at most) \$k\$ distinct, shortest paths connecting two given terminal nodes. You can see the previous version here. This implementation, ...
2
votes
3answers
137 views

Singly Linked List in pure C

I recently learned about linked lists and here is my first try to write one in C. I know it's a lot of code, but I hope someone takes a look. Any tips memory allocation and improvements are welcome. ...