19,935 questions
3
votes
1
answer
67
views
Trying to populate a list from another sheet by a single reference number
I am working on a handy reference sheet for my DnD Games, that includes 10 pre-planned encounters of varying difficulty that I want to reference on an Initiative Sheet by referencing the Encounter ...
Best practices
1
vote
7
replies
161
views
Memory allocation when using a linked list
So I'm making a linked list for one of my school assignments in C. I found this website that has some helpful code snippets, and I noticed that they use malloc() to allocate more memory every time ...
0
votes
1
answer
160
views
Reversing a linked list returns only the head
I have been trying to create a method that can reverse a linked list. However, it only show the head of the original list without the rest of the parts showing up. I have tried making another, similar ...
3
votes
2
answers
126
views
How to generalize a linked list node to store arbitrary data in C?
I’m trying to design a generic linked list in C where each node can store arbitrary data.
Right now I have the following definitions:
typedef struct {
int clientID;
char name[256];
} Client;
...
-6
votes
2
answers
168
views
Printing a linked list in C++ [closed]
I have simple question on C++ linked list. Say I am given a list, I just want to print for each node the value. I found this simple code on the net
while (head!= NULL) {
cout << head->...
1
vote
1
answer
96
views
Why does calling two functions in a single statement not affect the value? [duplicate]
In this code:
// Stack using LinkedList //
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node* next;
};
struct Node* top = NULL;
short isEmpty(void) {
...
3
votes
3
answers
354
views
ArrayList vs LinkedList in terms of cache locality
How does cache locality impact the performance of ArrayList compared to LinkedList in Java?
I've often heard that ArrayList has an advantage in terms of cache locality, but I don't fully understand ...
0
votes
0
answers
107
views
Using Merge Sort to Sort a Linked List with Inline RISCV ASM
I'm writing a Merge Sort to sort a linked list with inline RISCV asm, everything work fine until I start writing the part of lists merging.
Here is my function:
typedef struct Node {
int data;
...
-2
votes
1
answer
55
views
Print the contents of a Doubly Linked List [closed]
I am trying to print the contents of a Doubly Linked list using the str method by converting the content into string. The problem I face is that it returns the memory location of the values, not the ...
0
votes
2
answers
109
views
Rearrange linked list by position parity using single stack
I'm working on an algorithm to rearrange a singly linked list based on node positions using only a single stack as auxiliary space. The goal is to modify the linked list such that all nodes at odd ...
0
votes
2
answers
102
views
How to dynamically create multiple instances of struct in loop in C? [duplicate]
I have the following code to create one-way list of user-specified number of elements
typedef struct Node{
int val;
struct * Node next;
} Node;
int main(){
int num;
Node * prev = NULL;...
0
votes
1
answer
115
views
Shifting even numbers to the back of a linked list
I just started my college's data structures and algorithm's course and have some trouble with shifting nodes of even values to the back of my linked list. The function seems to work when there's only ...
1
vote
1
answer
71
views
Clarification on Recursion in mergeTwoLists for Linked Lists
I am trying to understand how recursion works in the following code for merging two sorted linked lists
class Solution {
public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
// ...
1
vote
3
answers
227
views
Deleting one node of single linked list use double pointers in C language
I have been reading something related to C language's double pointers, and I have some doubts about the following piece of code. The following piece of code is about the operation of deleting a node ...
0
votes
1
answer
75
views
In rust, How to allocate a large vector to a linked list without stack overflow?
I am doing problem 234 from LeetCode. I have a function which takes as its input a linked list:
impl Solution {
pub fn is_palindrome(mut head: Option<Box<ListNode>>) -> bool {
And ...
2
votes
1
answer
93
views
Turtle snake chain project
Below is a Python code for my "Snake Project" (with Turtle and Tkinter).
The purpose of this program is to create a chain of turtles, called followers, that follow each other, with the first ...
0
votes
2
answers
79
views
Merge K Sorted Lists - Maximum Recursive Depth Reached
I've been working on Leetcode problem #23: Merge K Sorted Lists:
You are given an array of k linked-lists lists, each linked-list is sorted in ascending order.
Merge all the linked-lists into one ...
2
votes
2
answers
107
views
How do I delete a pointer after assigning another pointer to that memory in C?
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
typedef struct node
{
int number;
struct node *next;
}node;
// create the pointer to the main ...
-2
votes
1
answer
56
views
How lambda expresison can reference to itself before instanciation? [duplicate]
For fun, I tried to create a linked list with lambda functions. I tried this little code as a first step, but my experimentation went short after facing an infinite loop:
import itertools
stack = ...
0
votes
0
answers
23
views
Seeking clarification on whether 'head' is an array of type ListNode, or is it just the 'head' node - LeetCode [duplicate]
I am seeking clarification on whether 'head' is the head of a linked list or it is an list of type [ListNode].
I think a screenshot of the question will bring more context so let me add it.
The ...
1
vote
1
answer
90
views
fgets() Overwriting part of a struct's data
So I am having a bit of trouble with this coding project, It is supposed to be a linked list with a bunch of fake students. I can get the first student in correctly, but when the fgets() runs again it ...
0
votes
1
answer
86
views
Single LinkedList
Currently doing my self studies/research about the Data Structure and Algorithm. I came with this tutorial.
I listen carefully on his lecture. However, when I'm implementing his code to my jupyter ...
-2
votes
1
answer
62
views
Running Java code in VS Code is not working unless I write the same lines over and over again [duplicate]
I wrote code for a linked list, adding a node. I use VS Code, but when I am want to run the code it's not working. This is my code:
package Linked_List;
import java.util.*;
public class Insertion{
...
-3
votes
1
answer
218
views
How do I iterate over a linked list and add nodes to it at the same time? [duplicate]
I have an algorithm that can be implemented by iteratively modifying a finite integer indexed collection of lists of objects of a certain class X. At every iteration, every object in every list should ...
0
votes
2
answers
267
views
Is using free(p->next) acceptable in C?
I'm working on solving a simple algorithm problem, and here's the question.
In a singly linked list L with a head node, delete all nodes with the value x and free their space. Assume that nodes with ...