linked-list

Recursively insert at the end of doubly linked list

橙三吉。 提交于 2019-12-12 06:15:26
问题 I have a doubly linked list, and I want to insert an element at the end of the list recursively. I have a method now that does this without recursion, and it works. I just can't seem to understand how to do it with recursion. Inserting at the end of a singly linked list with recursion is quite easy to understand I think, so I hope that someone can explain how to it do it when the list is doubly linked. Here is my normal insertion method that I want to make recursive: public void insert(T

Swap Position of the Node in C

ⅰ亾dé卋堺 提交于 2019-12-12 06:00:04
问题 Okay so I want to swap POSITION (not values) of two nodes. My Program is running with any errors or warnings, but I am not sure if I am swapping position or values. Here is my sort function: void sort(struct node **recordsHead,int (*compare_fcn)(struct node*, struct node*)) { void swap(struct node**, struct node**); struct node *tmp,*lastPtr = NULL; int swapped; do { swapped = 0; tmp = *recordsHead; while (tmp->next_ != lastPtr) { if (compare_fcn(tmp, tmp->next_)) { swap(&tmp, &(tmp->next_));

C user input and Linked List

Deadly 提交于 2019-12-12 05:37:21
问题 I am trying to intake a string from user input and then compare that to my linked list that i have created previously in the code and find the location as to where the string should be inserted. And stop looping when user enters nothing and hits enter. I am able to intake the string and find the location to insert, but what I want to do is to loop until the user enters a blank input. This is causing my code to break somewhere and I am not quite sure why. I have inserted break points in my

Adding element at nth position by passing linked list when passed by reference not working

你离开我真会死。 提交于 2019-12-12 05:28:07
问题 I am new to linked list this is my second problem after inserting element in LL.Now i am trying to insert element at nth position. I do so like this: (1) First taking the size of user at terminal. (2) Second read the input continuously from the user until the size. (3) I add the element read at terminal at the beginning of the LL. (4) I print that LL until formed. Until here everything works fine (5) Now after that i try to do addition at nth position in LL but it give 3 errors That i have

Linked List head not being updated across function calls

大城市里の小女人 提交于 2019-12-12 05:13:31
问题 I trying to implement my own linked list and have been messing around with the code learning about dynamic memory allocation and pointers and such. When I try to add something to my linked list I get a segfault, and upon using the debugger I realized that it was because initially my linked list's head pointer was not pointing to null and then my add function was not recognizing the head as being empty. But I have an initialize function that is setting the linked list's head pointer to NULL

Potentially uninitialized local pointer variable 'node' used. C++

二次信任 提交于 2019-12-12 04:59:43
问题 I am really new to C++ and this code was an example in my book so it should work because I have to implement a few new functions into this. However, I copied the code line for line and I keep getting this error message now my code won't compile until I fix it. It says that my local pointer 'node' is being used. I don't know what this actually means. Could anyone tell me whats is the error actually telling me? Also could some one help me fix this so I can start my project? I'm only asking for

Accessing nodes in a linked list after passing the list as an argument to a function, trying to setup multithreaded list

与世无争的帅哥 提交于 2019-12-12 04:53:47
问题 I'm trying to setup a multithread linked list. I think I have the initial list setup properly. As it says in the title of my post, I can't figure out how to get access to the nodes in the list to add the second thread. Here is the code that I have so far. void List::setListByName(Winery& winePlace){ Node * node = new Node; Node * curr = headName->nextName; Node * prior = headName; node->vineyard = winePlace; node->nextName = NULL; char newWine[CHAR_SIZE] = "Hi"; char currWine[CHAR_SIZE] = "Hi

Recursive function + linked lists. sprintf not saving variable into struct variable.

放肆的年华 提交于 2019-12-12 04:47:14
问题 The following code allows me to read a directory recursively and print all the files and their paths in a struct variable using linked lists. The problem I'm having is within the function when I print out the full path it shows it correctly but in the main when I was read through the linked lists, the fullpaths show up as null. Where am I going wrong? Code : #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> const char *path_format = "%s/%s"; typedef struct search

check if an element already exist in a linked list in c

ぐ巨炮叔叔 提交于 2019-12-12 04:41:00
问题 Suppose I have a linked list that stores a book struct and the next node pointer: struct book { unsigned short size_of_content; unsigned short price; unsigned char *content; }; struct list { struct book p; struct list *next; }; And when I am constructing the linked list, I will check if the new book's price is the same as the price of one of the books that have been linked. Basically make sure that there is no duplicate prices. I have an idea of constructing an price array and compare the new

Issue adding and deleting nodes from a linked list

一曲冷凌霜 提交于 2019-12-12 04:37:23
问题 I have a program that has to take in input from a text file, create a linked list with this input, then be able to add, delete, modify, and query the linked list. My query and modify functions work fine. My delete function fails under a particular case, and I'm struggling with the add function. No errors from the compiler to help out. It would be greatly appreciated if anyone could point me in the right direction. The add function is giving me the biggest problems. After a couple hours of