# LaVOZs

The World’s Largest Online Community for Developers

A linked list in which each node only points to the next node in the list, as opposed to a doubly-linked list in which each node points to both the next and the previous nodes. 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.

• ### Insert a node at specific position in a linked list in C (only)

Can anyone help me where I'm going wrong please !!!, I'm a beginner to programming, I'm new to DSA, I'm not able to find my mistake, here is the code please go through it: This is the outline of my ...
• ### Bubble Sort on singly linked list Worst Time Complexity?

I know that a singly linked list only points to the next value and cannot point to the previous value, so am I right to think that in a bubble sort the list would act the same as an array where it ...
• ### How to add an organ to a specific location in a linked list in C

I have a linked list, and two given words. I need to find the index of the first word in the list and then add the second word immediately after the first word. In the C language How to do it? Thanks ...
• ### Singly Linked List creation problem without using a function

//linked_list_1 #include<stdio.h> #include<stdlib.h> struct list { int data; struct list *link; }; int main() { struct list *ll=NULL, *tp=NULL; int n=3, i; ll=(...
• ### C++: Interleave (merge) two linked lists [closed]

I want to create a new linked list by merging two given lists. The new list contains new Nodes with the keys from the Nodes in list1 and list2, starting with the key of the first Node of list1, then ...
• ### Getting wrong answer with using a recursion func that finds sum of a linked list in C

I have two functions that finds sum of a very huge linked list.And recursive one does not give the true answer. (I have given the actual sum. So I know if the output is true or not) My code: float ...
• ### A question about deleting a node in a linked list

Before calling the free(); function if I don't assign NULL value to the link part of the node that I want to delete, what will be the problem ? I reviewed some codes of deleting nodes in other ...
• ### q.next=self.head AttributeError: 'NoneType' object has no attribute 'next'

the below one is code i tried for rotate a singly linked list by k. def rotate(self, k): p=self.head q=self.head prev=None count=0 while p and count<k: prev=p p=...
• ### Node deletion in linked list from beginning

I want to delete the first node and return the value of the deleted node. But I an getting this warning: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] example=(**...
• ### Cracking the coding interview 2.1 remove duplicate values from singly linked list javascript

class LinkedListNode { constructor(value) { this.value = value; this.next = null; } } let head = new LinkedListNode("head"); let x = [1, 1, 1, 1, 4, 10, 10, 3, 10, 9, 5, 5, 5,...

• ### Cant figure out how to display alphabets in order from a to z using linked list in c++

void alphaout() { nodealpha *curr; nodealpha *curr2; curr = first; curr2 = first; while (curr != NULL) { char al1 = curr2 -> alpha; char al2 = curr -> alpha; if (al1 < ...
• ### How can I delete multiple structs in linked list?

I have a problem: I got a struct with "movies" data. I need to search by "director" (char), and delete any records of "movies" data if it matches the same "director", as I entered by keyboard. ...
• ### Printing out elements of a linked list in reverse

I am practicing my data structures and trying out this problem on HackerRank on printing the element of a linked list in reverse order. I have looked through my solutions multiple times but I don't ...
• ### I want to free the last node from the memory before removing it's reference from the linked list. Can I do it this way?

Let's say temp currently points to second last node Then , temp->next =NULL; Will remove the last node from the list . But before doing that can I free the last node memory this way ? free(temp->...
• ### Sinlge Linked List, C++, problem with delete all and search functions

I tried to implement a single linked list. However, I have a problem with search and delete functions. Im getting segmentation fault, and I dont know why. Can someone probably explain me, what am I ...
• ### Linked list java declare type

This is my Generic list class public class GenericList T extends Object & IGenericNode T implements IGnericList T public GenericList(T element) { this.nodeRoot = new Node<>(); this....
• ### Difference in using * in Linked List in C++

What is the difference between (*current = *current->next)and (current = current->next)? My code is: class Solution { public: ListNode* deleteDuplicates(ListNode* head) { ListNode* ...
• ### Why can't I add a node to linked list in C?

I have a problem with linked lists in C. I made a function that created a new node of the list with some information (char *description) and added it to its end. The code is following: #include <...
• ### Patience Sort Using LinkedList of Stacks and Array

I'm trying to implement a patience sort algorithm that uses a data array and sorts numbers in that array into a LinkedList of stacks. Basically, I search for the leftmost stack, check to see if the ...
• ### How to swap a node in a linked list by passing nodes as arguements? [duplicate]

void swap(Node node1, Node node2){ Node temp; temp = node1; node1 = node2; node2 = temp; System.out.println(node1.value+" "+node2.value); } // calling swap in main ml.swap(ml....
• ### Adding value in the “nth” node of a linked list

I'm trying to add a value in the "n-th" node of a linked list. If n = 0, the value will be the head of the list. If n is greater than the length of the list, it will be the last node in the list. ...
• ### Linked List Stops after 2 nodes, why?

First post here. I'm trying to implement linked list with code below but somehow the linked list would stop after 2nd node. I was expecting 9->6->11->8->15->19->7->, but I got 9->6-> only. Can anyone ...
• ### Adding Node to End of Linked List in C causes Stack Dump

I am working on trying to add a node to the end of a linked list, but I am receiving cygwin_exception::open_stackdumpfile. Definition of my Node Struct: struct Node { int number; /* data ...
• ### why do I need to use strdup()? [closed]

typedef struct Node { char *word; struct Node *next; } Node; Node* newNode(char *word) { Node *n = malloc(sizeof(Node)); n->word = word; n->next = NULL; return n; } In ...
• ### LinkedList last value not getting parsed

I'm doing a leetcode question: Adding two numbers One of the testCases is not passing and I'm at the end of my wits as to why the last value is getting missed my my program. Here's the code: /** * ...

• ### Single Linked List, C++ segmentation fault, add to list, print

I want to implement single linked list in C++. I have a segmentation fault problem. I think it's the add function issue. Can anybody check and say how can I imporove this? #include <iostream> ...
• ### Insertion in Hash Table using Singly Linked Lists

I'm new here, I need some help with this problem, the problem is that it stores value for the first entry, but when I'm creating a list, for example when I want to insert 22, after I have inserted 2 ...
• ### Can't format “Add Two Numbers” output correctly in Ruby (Singly Linked List)

Trying to solve leetcode's "Add Two Numbers" problem in Ruby (https://leetcode.com/problems/add-two-numbers/). I know I have not solved the problem at all, just trying to make sure I can get my output ...
• ### What is the best way to make a singly linked list of integer digits in Python?

I am having trouble with producing a singly linked list in Python of the digits of an integer backwards. The output I'm getting makes absolutely no sense. The integer is as follows: ...
• ### Can't figure out why I am getting a segmentation fault when I try to append to the end of a linked list

I'm trying to practice and get comfortable with linked lists so i made this program to try to create nodes and add to the end of a linked list as it takes in data. Everything work until it gets to ...
• ### C - simple linked list delete first element which contains 'k'

I want to delete the element in a simple linked list which contains a 'k'. I am able to get the 'k' in name = popIfK(&kopf); Now in the function popIfK(...) I have to point with the element before ...
• ### Delete specific element linked list

Can you help me to understand why this function doesn't delete a specific element in the linked list? What am I doing wrong? typedef struct str_node{ int data; struct str_node *next; }node; ....
• ### loop for insertion in linked list not working

I'm trying to insert some nodes at the end of the linked list but something is not right in this code. Here I'm trying to make a loop and with the help of this loop I want the user to enter all ...
• ### Inserting a new node to a singly linked list doesnt work when i call the function in a loop

I am trying to append a node to the end of a list, so I wrote a simple append_node function. This function works fine normally but when I use a for loop , a extra node with a undefined value gets ...
• ### Why is my queue data-structure in javascript behaving the way it shouldn't

I have implemented a queue using linked list. I added a enqueue and dequeue function. As per the data structure, if after using dequeue, the item after 'front' item should become front but my code is ...
• ### Initializing a temporary variable in linked list python

In python, linked list creation includes creating two classes, one is the class node and the other one is the class linkedlist. In the class linkedlist , in the __init__() self.head=None is initiated....

• ### Java - Can I use a setter method to set a linked list node to another node?

[This question has been deleted]
• ### In java implementation of Singly Linked List, Why is the last element of the linked list not being printed?

public class Linked_List <E>{ public static class Node<E>{ private E element; private Node<E> next; public Node(E e,Node<E> n) { element=e; ...
• ### Missing a value from linked list

I write a linked list program that inserts the value in the first of the list, it's done, but the problem is that when I want to print the list than one value is missing which I insert the first. ...
• ### Build a singly linkedlist with this head line and main() code in C++

I'm a beginner. Recently, I got assignment. They say it's a simple method. But I can't help it. The question is build a singlylinkedlist using this <head line> and <main>, you can only ...
• ### The list is not filled in

I wrote a method that reverse the list, but as a result, the list remains empty. Help us understand what the problem is. Method for reverse the list: void reverseList(pLIST pL){ pNODE pN = pL-&...
• ### Deleting a specific node from singly linked list in C

I have made a singly linked list in C and I am trying to code a function which deletes a specific element from the list based on the integer value provided which corresponds to a particular node. ...
• ### Problems with my Polynomial class(Segmentation faults)

Problems with my Polynomial class(Segmentation faults) So i have made a Polynomial class for a school exercise but when i run it i get segmentation fault.If you could help i'll be grateful since i ...
• ### What are the differences in coding a destruction algorithm for destroying double and singly linked lists separately in C?

In my exam there was a question like this and I've been thinking that what are the differences in coding a destruction algorithm for destroying double and singly linked lists separately in C?
• ### if statement in search function linked list

I want to search in my linked list the string equal to x (parameter of function search) and return its value, but everytime the function return "doesn't exist" while idf in my list exists normaly. I ...
• ### How does Set work with Get in Singly Linked List in JavaScript?

I'm a newbie in JavaScript and trying to learn Data Structures and Algorithms. I'm struggling at understanding how set works by depending on getIndex. Here's the code: class Node{ constructor(val)...