Questions tagged [linked-list]

A linked list is a data structure where the list elements are not necessarily stored sequentially but rather each element contains a reference to the next (and optionally the previous) element in the list. This tag should be used with additional tags indicating the programming language being used ([c], [c++], [java], etc.) and any libraries or plug-ins being used such as [c++-standard-library]. The post itself should contain source code for the issue.

Filter by
Sorted by
Tagged with
-3 votes
0 answers
43 views

push_back for doubly linked list [closed]

I was working to make my push_back function work for the doubly linked list. And this is how I did it: Template <typename T> void List<T>::push_back(const T& newElement) { Entry* ...
prashantjerk's user avatar
-1 votes
0 answers
11 views

Is there a way to implement methods in MyLinkedList Class and if so how do I implement them?

I'm trying to implement methods for Chapter 24 Programming Project called Exercise24_01 and I'm trying to make it work. The code below is the code I have so far: import java.util.*; public class ...
RWorker's user avatar
1 vote
1 answer
98 views

How to visualize the creation of Linked-List in memory

I need clarification on the following C code which is used to create Linked-List in Heap memory using Dynamic Memory Allocation. The code creates a Linked-List by copying the elements of the array A. ...
Zzz's user avatar
  • 33
-1 votes
0 answers
44 views

Sorting in C++ using linked list [closed]

Consider there is a list of different gadgets that includes cell phones, smart phones and laptops with their prices and categories. You need to sort this items based on their categories. It means you ...
mehdi Shaikh's user avatar
-2 votes
1 answer
64 views

How to use (double) pointer to update value of other pointer

I am trying to merge an array of individually sorted linked lists together to one sorted linked list (this is Leetcode problem 23, BTW). The linked list is defined as: struct ListNode { int val; ...
Tim's user avatar
  • 11
-3 votes
0 answers
47 views

Why is this linked list code causing a segfault? [closed]

Hi I am experimenting with linked lists and I joined two on-line examples together and got it to run, but why does it cause a segfault at line 44? that's what the codeblocks debugger said. #...
Alistair Leech's user avatar
1 vote
2 answers
85 views

C++ synthesize linked list in constexpr

I have the following problem, consider a linked list like this: struct Element { struct Element* const next; // the const is required here constexpr Element(struct Element* _nxt) : next(_nxt) { } ...
johnworchester's user avatar
1 vote
1 answer
55 views

How do I make a linked list filled with random numbers and display them?

I am learning how to use linked lists. I need to make a linked list that is filled with 25-75 random integers 0-100 and then display them. For some reason when I run my program no output shows at all ...
Erin's user avatar
  • 13
0 votes
1 answer
67 views

How to register a template type as a valid value_type in STL algorithms

I am trying to write a custom container imitating the STL list. I have provided a Link class (not shown), some basic functionality and a custom bidirectional iterator. Trying to conform to STL ...
berkeozgur's user avatar
1 vote
0 answers
41 views

Understanding Basic Data Structures: Arrays vs. Linked Lists in C [duplicate]

I'm a first-year B.Tech student currently learning C programming. I'm working on a project that involves handling a collection of data, and I'm a bit confused about when to use arrays and when to use ...
BISWAMBAR PRADHAN's user avatar
-1 votes
0 answers
63 views

I can't write LinkedList

Can't finish the code I'm trying to write a linked list that contains structures River. I wrote all the functions seemingly correctly, but I can’t combine them, the code does not produce errors, I ...
JOKKEU TINKERINO's user avatar
1 vote
2 answers
59 views

Linked List delete node bug

Can't believe I'm asking this. I wrote a simple linked list and there seems to be a weird bug I cannot find. Please, help me. I add 1, then 2 to the front. Then I delete a node with value 2, which is ...
Sgg8's user avatar
  • 199
0 votes
2 answers
63 views

C function to find how many times a number reappears in a linked list

So I wrote this function in C that takes as a parameter a pointer that stores the address of the start of a linked list that contains several numbers(integers). It then returns the number of times a ...
konxanth's user avatar
0 votes
0 answers
18 views

Issues with the connection between the MS Access database and Dataverse/SharePoint List

I'm having an issue with a Microsoft Access connection. I have a Python code that exports a table to an Access database. When it is not linked to any other source such as Dataverse or a SharePoint ...
MrMonster1's user avatar
2 votes
1 answer
48 views

Design Linked List - Leetcode #707 - getting wrong output

I am trying to solve LeetCode problem 707. Design Linked List: Design your implementation of the linked list. You can choose to use a singly or doubly linked list. A node in a singly linked list ...
Marcus Mousavi's user avatar
0 votes
1 answer
77 views

Deleting item from a linked list causes segmentation fault because of referencing freed memory later

I'm working on a simple game that has a function where shooting an asteroid spawns 2 smaller ones. I've ran into a problem when I delete an asteroid that was hit and then try to add 2 new ones. Here ...
László Lipódi's user avatar
0 votes
2 answers
135 views

`free` in c doesn't free the memory, why? [duplicate]

I am trying to make LikedList Data structure from scratch. I made the structure: typedef struct ListNode { int item; struct ListNode *back; // point to the Node the before the current Node ...
Hasty__'s user avatar
  • 21
-1 votes
1 answer
47 views

I want to make a binary search using linked list

enter image description here Search Techniques Use appropriate variable names and adhere to coding standards. Handle user input and display output clearly. Use iterative/recursive binary search in ...
iEdit4Fun's user avatar
-1 votes
0 answers
44 views

RunTime Error - member access within null pointer of type 'ListNode'

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode() : val(0), next(nullptr) {} * ListNode(int x) : val(x), next(nullptr) {} * ...
Shrey Kumar's user avatar
2 votes
3 answers
166 views

How to sort an existing doubly circular linked list?

How can I change the location of a node in a previously created two-way circular linked list without changing the data in it? (First of all, I'm sorry for my bad English, English is not my native ...
Baran Kanat's user avatar
0 votes
0 answers
12 views

Selection Sort (Sorting Nodes not Values) in Double Linkedlist

I am trying to sort a double linkedlist, its node class is Weapon. I already tried the swap method for bubble sort and shell sort, it works fine. I don't know what part is incorrect in this selection ...
Chingu Dev's user avatar
1 vote
0 answers
48 views

Increasing the number of threads makes the program slower

I'm currently trying to implement a linked list with multithreading access to it by using read-write locks. Though it does seem to work correctly I've been trying to see what was the performance ...
Luca Mautino's user avatar
-1 votes
1 answer
72 views

my recursive function keeps going even after reaching the base case

this is a c++ recursive function, it's supposed to find a path in a linked list. I can't make it finish after reaching the base case. It just keeps going even after the return; void navigateGraph(...
Avi Moreno's user avatar
0 votes
2 answers
110 views

memory leak problem, destroy function is not freeing the linked list nodes created by my reverse function

my destroy_list(pHead1_reversed) and destroy_list(pHead2_reversed) function in my list_sum function doesn't seem to be freeing up the nodes. I'm getting a memory leak. What am I doing wrong? int main(...
cougarhound's user avatar
-3 votes
0 answers
18 views

Linked List Node Creation and illegal memory access

In C, in linked list when I want to create node then I write struct node *newnode = (struct node*) malloc(sizeof(struct node)); But my college professor says that if I write struct node *newnode = (...
Rishabh Chatterjee's user avatar
0 votes
1 answer
54 views

Linked list; TypeError: __str__ returned non-string (type NoneType)

I'm studying linked lists in Python 3.11. I wrote code given in the book. Code is below: class Node: def __init__(self, data, next=None): self.data = data self.next = next class ...
Elnur's user avatar
  • 13
0 votes
2 answers
219 views

Implement Queue using Linked List in C

This code is used to implement queues and some operations in C by using a linked list. I get unexpected output, especially the line "After removing front item: ", but I don't know why. Here ...
ahnherin092's user avatar
0 votes
2 answers
126 views

Implement Stack using Linked List in C

I have made this code to implement stack by linked list with some operations like add elements, delete, etc. There's some issue with my output, which is unexpected. If you can modify the freeStack(),...
ahnherin092's user avatar
-2 votes
0 answers
33 views

Printing Addresses Instead of Object Elements [duplicate]

I'm working on a Java program using generics, and I'm facing an issue where, instead of getting the elements of the objects, I'm getting their addresses when I print them. I have a GenericStack_llofob ...
Zeus Legend's user avatar
0 votes
0 answers
19 views

How do you make a Node class field member if the Node class is in a separate file? [duplicate]

This is a total noob question since I cannot remember. I want to make a homemade version of linked lists and my LinkedList class is as follows: package stacks; import java.io.*; class Node<T> {...
idkusrname126's user avatar
-1 votes
0 answers
24 views

MergeDLL functions solving with DLLNode and DLL

Given two doubly linked lists whose nodes each contain a natural number. A new doubly linked list should be created from these two lists, // in such a way that the nodes will be added alternately and ...
Andrej Aleksovski's user avatar
0 votes
0 answers
19 views

add the value stored in two linked lists and return a linked lists with the sum of the two numbers

my code seems to work, since it passes almost all the tests for this leetcode problem, however one of the tests is includes an extremely big value, which breaks my code. the test case in particular ...
Breach's user avatar
  • 1
-1 votes
1 answer
95 views

Why value of member variable is changing?

Here is a linked list: #include <iostream> #include <iomanip> #include <string> using namespace std; struct Arrival { string arrAddress; double distance; string ...
Roman's user avatar
  • 21
0 votes
0 answers
50 views

Is there some way to make an object into an array?

I'm doing this revel programming where it wants to implement certain stuff into MyLinkedList I think I got the gist of it but I'm still having trouble figured it out and revel wants me to use this: ...
RWorker's user avatar
1 vote
2 answers
44 views

Need help in understanding the pseudocode function that aims to delete an element in a specified memory address in a linked list

I was studying about Linked Lists from the book, "Introduction to Algorithms" by T Cormen. There was an portion in the book as follows: Given an element x in the list, x.next points to its ...
Thomas Finley's user avatar
0 votes
0 answers
6 views

How can I create a linked list in gforth

I asked Bing how I could create a linked list in gforth and it gave me the following example: Here is an example of how to create a linked list in Gforth: : create-node ( value -- ) HERE 8 ALLOT ...
Bryan Zimmer's user avatar
1 vote
0 answers
50 views

Why is my java function not working with my test case I have tried everything

this is my method public static LList subtract(LList list1, LList list2) { // Check if list1 is smaller than list2 based on lengths if (list1.length() < list2.length()) { // Swap ...
beech's user avatar
  • 11
-1 votes
1 answer
77 views

The swap and assignment operator calls themselves in linked list class, causing Stack Overflow

I'm getting this error from Visual Studio: Unhandled exception at 0x00007FF9E8AF8739 (ucrtbased.dll) in List.exe: 0xC00000FD: Stack overflow (parameters: 0x0000000000000001, 0x0000007E50C13FF8). I ...
o_22's user avatar
  • 11
-2 votes
2 answers
45 views

LinkedList null pointer error. I keep on getting a null pointer exception when trying to print the elements in the LinkedList [duplicate]

I Keep on getting a null pointer exception when trying to print the elements in the list. The exception hits the line in the print() where I start the while loop. Is there a way to fix this? Thanks ...
Amanda James's user avatar
0 votes
1 answer
34 views

How to print linked list in python without None error

I have a simple linked list I am building and I am able to print it in reverse order (first node added is printed last) but I would like to print it in normal order. However I am not sure why I keep ...
Rick J's user avatar
  • 3
0 votes
2 answers
64 views

How do I make the else statement to stop repeating output?

I'm just a beginner and badly needed help. I'm trying to make a simple inventory system using linked list with a search feature, I'm stuck on making this feature a complete success because my if else ...
idontknowwataymdoing's user avatar
0 votes
2 answers
44 views

Why can't I use head directly in this linked list problem instead of initializing and using ptr?

I was going through this solution for implementing a doubly linked list when I came across this doubt public class Solution { public static Node constructDLL(int []arr) { Node head = new ...
mysterymartian's user avatar
0 votes
1 answer
77 views

Problem with deleting a desired element of the linked list in C

I came upon a problem in which i can not delete a element of a linked list with a given position. I need to delete a element with a uneven value (my list are numbers form 1 to 100 included). Here are ...
muniek7's user avatar
0 votes
1 answer
34 views

Which is more efficient : stacks using array or stacks using LinkedList (for large data) & why?

Which is more efficient in terms of time complexity & space complexity: stacks using array or stacks using linked lists (for large data) & why? Please explain in as much detail as possible. ...
Kartik Saini's user avatar
0 votes
1 answer
46 views

What's wrong with the coefficients in this linked list implementation of polynomial addition?

I use linked list to implement polynomial in Java, every node in the linked list contains two int values(coefficient and exponent) and a pointer next. public class Node { public int coef; ...
DL32's user avatar
  • 1
0 votes
1 answer
82 views

Why does accessing the cells of my hashtable return question marks?

I would like to fill in a hashtable with characters read from a user inputted file as character arrays (i.e. character arrays whose first element is a character and whose second element is the NULL ...
M K's user avatar
  • 17
0 votes
1 answer
41 views

Null condition not showing output

struct node *position(int key) { struct node *p1 = head; while (p1->info != key && p1 != NULL) { p1 = p1->link; } if (p1 == NULL) printf("...
Risher322's user avatar
0 votes
1 answer
53 views

Why circular list doesn't solve Josephus problem?

I am working on the program which solves Josephus problem on C. I have to use circular linked lists here. Currently I have this code to create list: void create_list(int N, struct node* head){ int ...
Azizbek Sattorov's user avatar
-1 votes
1 answer
39 views

Two pointers algorithm vs. Floyd's cycle-finding algorithm vs. Hare & tortoise algorithm vs. fast & slow algorithm. What is the difference?

When studying the cycle-finding algorithms, I frequently come across these expressions and I am not sure whether they are merely synonyms or there are difference between them.
Rubem Pacelli's user avatar
0 votes
0 answers
66 views

Find the longest subsequence with minimum sum of contiguous nodes in a circular linked list with at least K elements?

The problem is I have a circular linked list, for example: -12->-55->47->-33->-25->14 I want to return a sub sequence of this linked list with at least 4 elements(the answer is -33->-...
smulslippy's user avatar

1
2 3 4 5
396