Questions tagged [linked-list]

1

votes
1

answer
125

Views

Lockfree linked list

I am implementing a lockfree linked list in C, similar to what's available in linux kernel llist.h. I am using atomic operation of '__sync_bool_compare_and_swap'. Here is the code snipet: struct llist_head { struct llist_node *head; struct llist_node *tail; }; struct llist_node { struct llist_node *...
chris.sun
1

votes
1

answer
84

Views

How to move elements from one linked list to another in order

What i need to do is to copy the linked list list1 already filled with these values: 0000001 3 0000002 2 0000003 1 0000004 1 and paste them with the function CreateMenuList() into another list called list2, so that every element of list2 has the members of list1 matching a particular num...
St3ve R0nix
1

votes
1

answer
50

Views

C - Can I use the same functions for these two different lists?

A uni project I have involves sorting a very large set of data into two different lists, one which has a bunch of data on a city or country, and another which has that same data (on a city, this time), but also with some coordinates, like so: //used for cities and countries in the textual mode typed...
1

votes
0

answer
72

Views

free() function in c on a struct generates a breakpoint without any error code

I'm trying to create a linked list of users in a social network in c. I have 2 modules: User - a struct which contains a username (char), number of friends(int) and a linked list of friends (each block in the list contains a name and a pointer to next friend of the User).the User module has methods...
Zuser
1

votes
0

answer
42

Views

Generic Single Linked List, No Viable overloaded =

I am creating a generic single linked list for the first time. I have this error that states: No viable overloaded '=' So I decided to overload the '=' operator to make it work but I am still receiving the same error and I am not sure why. Here is my header file: #ifndef LinkedList_hpp #define Linke...
Snorrlaxxx
1

votes
1

answer
68

Views

C++ Linked List — Reading in a file and sorting it based on number

I am working on reading in a file. It is filled line by line with things such as the following: e 2 b 1 a 3 h 5 c 4 If I were to sort these by the number I would get the word 'beach'. I need to do this but at a larger scale. I currently have two errors. There are lines I read in which have a spa...
corin
1

votes
3

answer
38

Views

Deleting LinkedList With Specific Value Only Once

I'm writing a program and in one of the functions I have to remove a value from a LinkedList struct node *delete_val(int value, struct node *head) { struct node *h1 = head; if (head == NULL) { return NULL;} if (head->next == NULL) { free(head); return NULL;} while (h1 != NULL) { if (h1->next != NULL...
oAUTHo123
1

votes
2

answer
42

Views

Deleting LinkedList Last Item

I'm writing a program and part of this program is a function that has to delete the last element in a LinkedList: struct node *del_the_last(struct node *head) { struct node *h1 = head; if (head == NULL) { return NULL; } while (head->next != NULL) { head = head->next; } free(h1); return head; } Gi...
oAUTHo123
1

votes
1

answer
44

Views

Last item is skipped by custom sorting/removing of duplicates in linked list

I am trying to write a code in c to remove duplicates in singly linked list. I am doing it by first inserting numbers through dynamic allocation and then sorting the list and then finally removing the duplicates. The code is working for all cases except if the last number is itself duplicate then th...
1

votes
0

answer
26

Views

Save LinkedList to Parse Server

I'm trying to build a Single Linked List using Parse PFObjects. Each PFObject has a pointer to the next object in the list. I can pin them locally, but I'm having an issue when saving them to Parse Server. The problem start here: + (BFTask *)_deepSaveAsyncChildrenOfObject:(id)object withCurrentUse...
Pau Senabre
1

votes
0

answer
57

Views

C++, Pointers, Merging of two sorted linked lists

I took reference of code from GeeksForGeeks for merging of two sorted linked lists. #include using namespace std; /* Link list node */ struct Node { int data; struct Node* next; }; void MoveNode(Node **destRef, Node **sourceRef){ cout 20 */ push(&a, 15); push(&a, 10); push(&a, 5); push(&b, 20); pus...
Abhijeet Bhure
1

votes
3

answer
55

Views

Delete operator

void createnode(int data) { node *temp=new node; temp->data=data; if(head==null) { head=temp; tail=temp; temp=null; } else { tail->next=temp; temp=null; } } Should I delete temp right now? I'll be using another function to delete every node. Will that be enough?
Basil Kuriakose
1

votes
0

answer
57

Views

list_empty is returning true after some iteration.

I'm writing V4L2 driver by referring vivi.c driver from linux kernel https://elixir.bootlin.com/linux/v3.17/source/drivers/media/platform/vivi.c#L875 static void vivi_thread_tick(struct vivi_dev *dev) { struct vivi_dmaqueue *dma_q = &dev->vidq; struct vivi_buffer *buf; unsigned long flags = 0; dpri...
1

votes
1

answer
74

Views

How to check whether linked list is circular or not without using extra memory or variable?

How to check whether linked list is circular or not without using extra memory if the head is given
Nitkarsh Gupta
1

votes
1

answer
143

Views

2 singly linked list intersection

I'm trying to create 2 single linked lists and find the intersection between them. I'm getting errors such as NameError: obj is not defined for the LinkedList line and would like a working solution. How do I make this work? What am I doing wrong? Am I even close? What is the meaning of life? T...
RyanWolfe9013
1

votes
1

answer
146

Views

Python: Remove Node Linked List

I am fairly new to Python and am trying to delete a node from a Linked List (not the tail) and am getting the error: AttributeError: 'int' object has no attribute 'next'. Clearly, something is wrong with delete_middle_node, but I'm not understanding what! EDIT: complete error message is: Traceback...
dmcdekker
1

votes
1

answer
51

Views

Insert position for a single linked list using unique_ptr

I am trying to implement a the insert position function of a single linked list using unique_ptr. I was following a similar implementation online that used shared_ptr but I cannot get my function to work and I get this error I do not really understand: 1>------ Build started: Project: LinkedList, Co...
Wolfy
1

votes
0

answer
15

Views

how can i pass a struct inside a linked list?

I'm new to c language, I always find this site very helpful but could not find a clear answer to this problem. im having a hard time to send a struct with 3 fileds as a linked list value. this is the function: void add_to_list(list *s, find_indexs * q) { list_node* ln = (list_node*)malloc(sizeof(li...
netanel94
1

votes
2

answer
62

Views

Segmentation fault:11 in my code for creating a linked list in C

So I'm very new to programming, so I would like you to keep in mind theres a high chance I've made a very dumb or basic mistake. I have run into this problem while trying to create a linked list in C. For the output, I'm able to enter 2 elements before I get a segmentation fault:11. #include struct...
onesandzeroes
1

votes
0

answer
156

Views

AttributeError: 'function' object has no attribute 'get_value'

I receive the AttributeError only after the value is successfully deleted - Please suggest if there is anything wrong in the way the values are printed. The function prints correctly prior to a Delete class Node: def __init__(self, value=None, l_next=None): self.value = value self.l_next = l_next de...
Vivekan S
1

votes
1

answer
35

Views

Linked List Choke Python

I have an assignment on Linked List, and the name of the game is to add words from a string into an array implemented linked list, which is alphabetically ordered with pointers. However, when I run the following code, the Python Shell gets stuck and no results come back. Please help! Thank you! I t...
GenjiMain
1

votes
1

answer
130

Views

MapReduce-KNN for Hadoop - run multiple test cases from one data file

Background: [Skip ahead to next section for exact problem] I am currently working on Hadoop as a small project in my University (not a mandatory project, I am doing it because I want to). My plan was to use 5 PCs in one of the labs (Master + 4 Slaves) to run a KNN algorithm on a large data set to fi...
vinit144
1

votes
0

answer
13

Views

Linked list: stored elements are not displaying completely

I am trying to store 5 elements in linked, the input code is working fine but the display code is not showing the 5th element 'RollNumber'. I can't find where I did the mistake. class Node { friend class LinkedList; private: string BookName; string BookNo; string Price; string StudentName; string Ro...
Hami
1

votes
1

answer
44

Views

Python Linked list removal of node at the end

I am implementing LinkedList in Python 3.6.5. I am stuck with deleting a node from the end: Here's the code: class Node(object): def __init__(self, data): self.data = data self.nextNode = None class LinkedList(object): def __init__(self): self.head = None self.counter = 0 def print_list(self): curre...
Ritwik Tiwari
1

votes
3

answer
52

Views

Should I use linked list or list and how do I serialize it.

This is for c# I'm an old dinosaur, writing 360 assembler since the 70's, trying to write stuff for the PC. Along the way I am replacing my old write it myself thinking with use the existing infrastructure. Here is what I have now. Two objects, System and Planet. A field in System has a pointer to...
Peter
1

votes
1

answer
59

Views

values of a object stored in a linked list printing but not useable

I am fairly new to java and working on a project to simulate a CPU scheduler in Java and i am using a linked list to store each process object that is read in from a external master list. When I test print the processes and the variables they contain, everything comes out as expected but whenever I...
Nat D
1

votes
0

answer
94

Views

Reversing a linked list using stl

I am trying to implement reversing of linked list data structure using vectors and standard library.I am getting an error ‘::system’ has not been declared using ::system; #include #include #include using namespace std; int main() { vector v[100]; vector v1; int n,i,k,j,x; cin>>n; for(i=0;i>x...
Ayush Mishra
1

votes
2

answer
89

Views

Pushing an element onto the stack using linked lists

why when pushing an element onto stack do you return the head pointer? Is this necessary or just good practice? Thank you so much, i think i'm missing something. For example: struct node* push(struct node* head,int data) { struct node* tmp = (struct node*)malloc(sizeof(struct node)); if(tmp == NULL)...
MangoKitty
1

votes
2

answer
123

Views

Adding a node to the head of the linked list

I would like to add a node in a sorted linked list based on the number. This is the struct: struct node { int number; struct node *next; } I am able to add to the sorted linked list correctly but can't get it to change head. Unfortunately I can't change the format of the function declaration so this...
Ibrahim Abouhashish
1

votes
0

answer
93

Views

Double linked list, insert at position

I am studying for some interviews coming up and I am practicing writing some of the common data structures out for practice. All my functions so far work great except for the insert_at_position. When I try to insert into the beginning node of value 1 I get two values for 1 and I am not sure why. Her...
Snorrlaxxx
1

votes
1

answer
66

Views

Insert n amount of values to an empty doubly linked list (pseudocode)

Can someone help me verify if my pseudocode works correctly so the function presented appends n numbers to a list? I need help with an assignment on my first year on data-science. We are learning about data structures and about doubly linked lists. I understand the logic behind doubly linked list...
jubibanna
1

votes
1

answer
127

Views

Linked stacks and queues

Came across Linked Stacks and Queues in a book(and it is not stack/queue implementation using linked list). it says that stack/queue can be represented sequentially if we had only one stack/queue.However, when several stacks/queues coexisted ,then there is no efficient way to represent them sequenti...
Praveen Parihar
1

votes
0

answer
68

Views

In a reversely linked list, how to get a sublist of it efficiently?

Supposed I have a reversely linked list, i.e. a data structure where each node points to its predecessor: A
Golo Roden
1

votes
1

answer
78

Views

Character counting with a Linked List

I am trying to Design a program that reads an ASCII text file one byte at a time and outputs the frequency count of how many times each character appears. The output does not need to be sorted. The character frequency objects need to be processed and stored using a Linked List. I know that my charac...
apaige
1

votes
2

answer
101

Views

Linked List Python

class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None def __len__(self): cur = self.head count = 0 while cur is not None: count += 1 cur = cur.next return count def append(self, item): cur = self.head while cur is not None: cur...
1

votes
0

answer
62

Views

Adding an entire array to a linked list

Hello everybody I have a question regarding adding an entire array to a linked list and what I mean by that is not adding the values with an int array to a linked list but to store the array itself within the linked list. For example int[] numbers = new int[1,2,3]; LinkedList hi = new LinkedList();...
Dave
1

votes
0

answer
47

Views

C++: Store data in Linked list in another linked list

I would like to ask how to store the linked list of Opt in linked list of CustomerData? The approach that I use right now is creating the two linked list separately. When I need print out all the receipt the I have key in, I need to use the if statement (optical_data.currentOpticalTrace == customer...
aeiou
1

votes
1

answer
174

Views

Correct way to delete a node in doubly circular linked list

The purpose of this code is to manage insertion and deletion and visualisation. I just want to know if I'm doing everything correctly, let me know if there are more possible ways to do this. This is my first attempt, i didn't follow any tutorial. #include #include #include typedef struct Node { i...
Stefano Raneri
1

votes
1

answer
53

Views

Sorting linked list from biggest to smallest

I have sorted my linked list with this code. It sorts it from smallest to biggest due to data2. e.g: my list's output was : 1. data1: 3 data2: 4 2. data1: 7 data2: 3 3. data1: 5 data2: 0 4. data1:-6 data2: 2 5. data1: 4 data2: 1 and it made it to this: 1. data1: 5 data2: 0 2. data1: 4 data2: 1 3. d...
Deniz Akpınar
1

votes
1

answer
47

Views

'AttributeError' in linked list in Python

This code deals with removal of duplicates from a linked list in Python. The problem seems to be in the remove function. class Node(object): def __init__(self, data = None, next_node = None): self.next_node = next_node self.data = data #get data at that location def get_data(self): return self.data...
user22430

View additional questions