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
3answers
267 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
380 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
3answers
146 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. ...
3
votes
3answers
216 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
2answers
8k 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
3answers
904 views

Linked List design and implementation - C++

Seeking recommendations on how to improve this code, LL always seem to be a struggle. A basic linked list that does include next and previous pointers. I used a struct inside of a class, which I'm ...
3
votes
2answers
672 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
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
2k 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
107 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
217 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
2answers
436 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 ...
2
votes
1answer
71 views

Printing heads of stand-alone lists

Please review my code to help improve its quality. ...
2
votes
1answer
143 views

Double LinkedList Deep Copy in Kotlin

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 ...
2
votes
2answers
55 views

remove kth last element from singly-linked list - Follow up

This code is a revised version of implementation which asked for an improvement. Original question is asked here: remove kth last element from singly-linked list credits to: Toby, Andreas, Arkadiusz ...
2
votes
0answers
84 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
1answer
791 views

Designing function prototypes for a singly-linked list API in C

I am in the process of rewriting in C all the data structures that I learned about a few years ago to increase my understanding of data structures and the C language. The first one I'm doing is singly-...
2
votes
2answers
72 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)....
2
votes
4answers
245 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 ...
2
votes
1answer
86 views

Singly linked list in pure C - follow-up

This is an update for this post. I fixed all style-issues from the comments, but still have a few questions left: Someone commented that my last post contained too many functions, which could be ...
2
votes
1answer
93 views

Populate the list based on which datacenter code is running on

This is a follow on to : Efficiently detect datacenter based on server hostname and return the full path. I have a library which is running in different datacenters in production. I have three ...
2
votes
1answer
740 views

Generic Macro Generated Linked List in C

Generate a linked list of any type using macros. The linked list contains functions for adding and removing elements to both ends and also at the middle. You can also add elements relatively to a list ...
2
votes
1answer
286 views

Linked list implementation along with unit test - Round 3

Here are the changes I've made thanks to suggestions made by @vnp, and @Henrik Hansen. Here is the link to the previous code review: Linked list implementation along with unit test - Round 2 I've ...
2
votes
2answers
114 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 ...
2
votes
1answer
555 views

Optimizing twin() method

Part III of this question says: Fill in the twin() method in the SList class so that it performs as indicated in the ...
1
vote
1answer
76 views

Rotating lists in linear time and constant space (Java) - follow-up

(The previous and the initial iteration.) After some critique, I found the way to keep the rotation operation also for java.util.Lists that do not provide random ...
1
vote
1answer
97 views

Revision-2 C++ implementation of a linked list

I have addressed all your comments in my previous post. C++ implementation of a linked list Can you please comment on, How efficient the code is? Am i using too much extra variables to implement ...
1
vote
1answer
513 views

Working C code dealing with lists: problem with memory leak

I have written a working code that generates a simple linked list of dates and associated holidays. I realize that I have a problem with memory leaking as I copy lists repeatedly, so I wrote a ...
1
vote
2answers
80 views

remove kth last element from singly-linked list

I have implemented a code to solve following problem. I would like to improve the code efficiency. Pardon if I just printed out the result. Code has O(N) time and constant space complexity. Given a ...
1
vote
2answers
197 views

LinkedList Implementation in Java

Please review my implementation. I know there is already an implementation in Java, but I just wanted to come up with my implementation. Let me know if I can improve this. ...
1
vote
1answer
222 views

Linked List Interview Code methods, runtime, and edge cases

Refactored code here I want to write a very simple Linked List with only 3 methods Append, Remove and Print. This is not for production and is to be treated as code that could be used in an interview ...
1
vote
1answer
234 views

OOP paradigm implementation of a linked list

Can this code be improved from an OOP paradigm perspective? ...
1
vote
1answer
761 views

Delete node from singly linked list with tail pointer in C

I'm trying to implement a single linked list based on Linus' comments about double pointers. In my case I'm also using a tail pointer and I'm wondering if there's a better way to update the tail ...
1
vote
2answers
1k views

Check if a linked list is a palindrome in O(n) time and O(1) space

I liked this problem because there are so many sub-problems that are interview problems in their own right-- (reverse linked list, find midpoint) ...
1
vote
1answer
1k views

Rotating a matrix in Java

Introduction This program is about rotating a matrix. For example, let the matrix be abcde fghij klmno pqrst Now, after rotating two steps clockwise we will ...
0
votes
2answers
89 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. ...
0
votes
2answers
5k views

C++ remove from singly linked list

I asked a similar question (C++ linked list) but I'd like to have this similar code reviewed. It's not the same code, just slightly different and with bugs fixed. The code takes the head pointer of a ...

1 2
3