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
0
votes
1answer
25 views

Class with Struct Inside of it is not Instantiating (Segmentation-Faults Right Away)

What I believe I'm doing is implementing a queue using a circular linked list. It segmentation-faults as soon as I instantiate a Queue object. Researched the issue, but at this point, I've got no idea ...
5
votes
3answers
77 views

Why does freeing the memory lead to segmentation fault?

I´m desperate because this code form time to time gives me a segmentation fault and I have no clue why. Actually it´s only supposed to add some linked list notes, print them and then empty the list by ...
0
votes
1answer
20 views

What is the time complexity to insert M elements in a singly circular ordered list?

On a singly circular ordered list having N elements and if M elements are to be inserted what will be the complexity of time? a) O(M*N) b) O(M*(M+N)) c) O((M+N) * log(M+N)) I think, the time ...
0
votes
2answers
36 views

Inserting into LinkedList and then Sorting by Ascending ID number

I have random ID numbers assigned to my list items. I have a class containing the LinkedList, and a class representing the items in the list. This is what I have to do: The constructor in the ...
1
vote
1answer
14 views

The display function doesn't execute , the head value keeps getting set to null so the display function keeps printing empty

#include <stdlib.h> #include <stdio.h> struct node *create(int num); void display(void); //linked list node creation struct node { int data ; struct ...
0
votes
1answer
49 views

How to initialize a doubly linked list with the following structs?

This is my code, I know I did not write much, but I am not knowing how to initialize a doubly linked list with the given structs. The given structs (I can`t change anything in them) /* a node in the ...
0
votes
0answers
25 views

Not working sorting in programme with Doubly Linked List on Python

I am writing a programme on Python which is imitating work of Doubly linked list but this algorithm is not working. My knowledge about Python is not so good, so. Please help me to fix it. It's a code:...
0
votes
0answers
49 views

I'm trying to reverse a linked list using a stack

So, I've already managed to get the linked list to work from user inputs but now i'm stuck on passing that list to a stack. (I have the functions created from a previous code I made under comments) ...
2
votes
1answer
37 views

I must build a contact list using a linked list in c++. It currently infintely loops the third contact

I was given a class declaration and a main and I must create a class definition without altering either. I understand the concepts pretty well, but I don't have the syntax down at all. The while loop ...
0
votes
1answer
16 views

How do I sort nodes by CPU time in linked list as they are put on the “queue” in CPU scheduling simulation C program (SJF)?

Below is the two relevant functions for my question, but please ask if you require any of the other functions to help me solve this problem. This program simulates a single server queue with ...
1
vote
1answer
26 views

How to get forward iterator that starts from the last element

I have a LinkedList. Suppose that I'm inserting an element at the end and I want to save the position where was it inserted, so that I can call a function on an element next to it, whatever manages to ...
0
votes
0answers
36 views

Problem while saving data into a linked list in C

I'm developing a program that read some path from an input file passed as arguments and then read recursively or not the path it contains and saves them into a structure. The input file is the ...
-3
votes
0answers
27 views

binary tree in c with one list to list all the nodes and another to indicate the number of nodes at each level

Here's the question: There is a family tree numbering method that allows us to represent a complete tree in tabular form. The root is stored at position 0, the left child of the root is in position 1 ...
0
votes
1answer
42 views

Set values are getting updated in all the list variables

I have a complex structure like ArrayList<LinkedList<Struct>> In my main class I have 2 nested classes as below static class struct { private String name; ...
-1
votes
1answer
27 views

Recursively reversing a linkedlist with only two pointers returns?

I'm trying to recursively reverse a linkedlist with "only" two pointers. In reality, each recursive call temporarily makes a third pointer to assist it. I have a certain algorithm I am trying to make ...
0
votes
1answer
29 views

Am having difficulties with linked lists

I am trying to learn linked lists and I am just making this program for practice. It contains several linked lists made from two structs. Everything from the struct letterLink works fine (typedef ss) ...
0
votes
1answer
49 views

linked list interview queston

So the question is: *Given a (singly) linked list with head node root, write a function to split the linked list into k consecutive linked list "parts". The length of each part should be as equal as ...
0
votes
0answers
40 views

BigInteger represented as linkedlists [on hold]

Looking for a efficient approach to doing the multiplication operation on a linked lists of long integers. Constraints for this problem are: 1) the big integer is represented as a linked list with ...
2
votes
1answer
33 views

Linked list implementation in python 3

I am still a beginner in programming. I learned the basics in Python. Right now I'm learning data structures and algorithms. I have implemented a linked list. But there is a problem inside it. My ...
0
votes
1answer
27 views

How to convert the given Before Links to the After Links using a couple of lines of code in Java?

Before: +----+----+ list-->| 1 | / | +----+----+ +----+----+ +----+----+ +----+----+ list2-> | 2 | +----> | 3 | +----> | 4 | / | +----+----+ +--...
1
vote
1answer
46 views

How can I insert value in a char array?

I'm trying to create a linked list and save the value "Peter" in the first list element. I'm having a problem with the char array. I can't insert "Peter" in it. #include <iostream> ...
2
votes
1answer
48 views

How to use Cons in Scala when implementing a linked list?

I have been trying to implement a linkedList in scala for a university course. So far I have implemented the Empty and the Constructor Cons and a few more methods. Right now I try to implement the ...
-2
votes
1answer
49 views

Repeated Segmentation Fault while deleting from a Linked List in C

For an assignment we are told to create a Dictionary Abstract Data Type (ADT) which is based on a linked list structure in C. From all my tests using the required functions size insert (being done ...
0
votes
2answers
43 views

Why am I counting one less in following code that counts number of elements in linked list

I am unable to figure out why am I counting 1 less in len() function defined below. len() function is supposed to count the number of elements in my linked list. struct node { int data; ...
-1
votes
2answers
57 views

Can we implement a link list without using the head pointer means by using a simple variable of the head instead of the pointer of the head?

Can we implement a link list without using the head pointer means by using a simple variable of the head instead of the pointer of the head ?
0
votes
0answers
75 views

What do I not understand about memory leaks?

For a class I am taking, we are implementing our own singly-linked list in c++ so that we can better understand how the data structure functions. Currently, I have completed the code, which passes all ...
-2
votes
0answers
26 views

Write functions for finding and sorting for doubly linked list on python

Good day. I am begginer in python. And I am writing programme that realise a work of doubly linked list on Python language. It's my code: https://pastebin.com/0ciZyzeB # We define the basic class ...
0
votes
0answers
30 views

Adding to Front of Doubly Linked List, Why is my List Incorrect and Getting Printed out Backwards?

Creating a doubly linked list (has head and tail pointers). I've made functions for adding to the list and printing out. The output I'm getting shows a problem but after staring at it for some time, ...
-3
votes
1answer
35 views

It doesn't display the data, it only shows never-ending loop

I'm getting a never-ending loop. What did I do wrong in this code? Thank you so much for helping me out. void viewStudents() { student *current = head; do { if(current == NULL) ...
0
votes
1answer
14 views

BJP5 Exercise 16.7: deleteBack — Help me understand the solution

I have been working on this exercise to practice ListNodes, and was very frustrated because though I thought I wrote the code correctly (as shown below), it didn't let me pass: public int ...
0
votes
0answers
33 views

Problem in linked list while using struct variable

Code for linked list using memory allocation: #include<stdio.h> struct node { int val; struct node *point; }; int main() { struct node *head; head=(struct node* ) malloc(...
0
votes
1answer
24 views

How to convert the given Before links to the After links using one to two lines of code in java?

Before: +----+----+ +----+----+ list ----> | 1 | +----> | 2 | / | +----+----+ +----+----+ +----+----+ +----+----+ temp ----> | 3 | +----> | ...
0
votes
5answers
53 views

Add a node it its proper place (list will be in ascending order)

I am trying to a add a node in its proper place (in ascending order). So when the user enters a number, then its value will be automatically stored in a memory location. For example the user entered ...
-1
votes
0answers
75 views

How to fix exit code 35584?

I have struct called Matrix typedef struct Matrix{ const char* name; int** matrix; int row; int column;}Matrix; Then i created linkedlist to store these matrixes and created a function that travels ...
-3
votes
3answers
84 views

Why do I get segmentation fault if I don't use “new” keyword?

The following code generates segmentation fault. I don't get segmentation fault if I allocate memory on heap for my node1. (Node* node1 = new Node). My question is why do I get segmentation fault now? ...
0
votes
1answer
39 views

Incurring in segmentation fault problems with doubly linked lists in C

I'm trying to insert nodes at the front of a doubly linked list using a function, but I get a segmentation fault error and just can't understand what the problem is. For the typedefing of the pointers ...
0
votes
0answers
36 views

Eclipse suspends my process in debug mode

So I am working on a project involving Linked Lists. We have to make the Nodes and the Linked Lists ourselves (not allowed to use the Java provided ones). As part of the project, I am making a list ...
1
vote
2answers
63 views

C Battleship Game Linked List print_node function

I've been working on a battleship program in C for a class and I am having trouble with my print_node function returning the values from my head node (currentState, ship_type, charInput etc.). Each ...
0
votes
2answers
52 views

How to implement doubly linked list without using tail pointer

Is it necessary to have a tail pointer in doubly linked list? How to implement doubly linked list insertion without tail pointer, what would be the time complexity if we do so.
-3
votes
0answers
13 views

What are the real life uses of an Unrolled Linked list?

I've recently been given a task to create a fully working Unrolled Linked List (ULL) data structure. I understand how it works and how to correctly implement it, although I do not know where it could ...
1
vote
1answer
27 views

why does my LinkListCreate function stop running?

I want to creat a link list by CreateLinkList(LinkList *L, int n), but the output of printf is 0 1 only. It seems to stop at line 3 in CreateLinkList. How can I fix it? void CreateLinkList(...
0
votes
0answers
56 views

Segmentation fault when returning a linked list from a function

I had the following code, which prints the files in a folder that have an ending. It looks also by default files with the following ending "SCL_10m.tif". This is the version that worked so far: #...
0
votes
1answer
29 views

basic questions about Linkedlist and Node Insertion

I have some problems about my sub-major lecture. First of all, sorry for poor English. anyway, Professor told me that It was very east to solve, just change some lines and it would be work. but I ...
-1
votes
1answer
61 views

I'm reviewing c for my own edification. This code is for a sample linked list. I don't understand the pointer logic

This does not compile under Microsoft using cl (error msg below - what is it complaining about?) but it does using gcc. Can someone explain in plain English the following line? Is there some code ...
0
votes
2answers
46 views

How can I only refer to an object ONLY if it actually exists?

I am implementing a stack using linked list in java. The problem is that I get a nullPointerException when there is no element below, e.g. the StackNode.link does not exist. Therefore if I try ...
1
vote
1answer
77 views

Problem with pointers to three different linked list

I'm having problem with pointers in a C program that count the occurrences of a string or more in a bunch of file. The program take in input a file which contains the paths of the files in which ...
-1
votes
2answers
43 views

Using enhanced for loop to search LinkedList

So im trying to replace a for loop with a enhanced for loop and i cant get it to work, the problem is that it does search and when it finds the name im looking for it returns inex -1. With the normal ...
-1
votes
1answer
36 views

How do I use a function to return two different linked list?

I am working my way in the following code: #include <dirent.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include "gdal/gdal.h" #include "gdal/cpl_conv.h" #...
0
votes
0answers
8 views

How to connect two seperate linked list in seperate H files to one connected linked list

I am trying to make a Concordance involving two linked lists I have made. One of the list is in a file called "Alphabet.h" and the other list in a file called "Words.h". We need to connect these ...
0
votes
0answers
21 views

I got an error on insert the object into a linked list array

int i=0; LinkList ls = new LinkList(); int total=0; private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Hidden.setText(" "); DefaultTableModel model = (...