linked-list

mysql query for linked list

∥☆過路亽.° 提交于 2020-01-02 06:12:11
问题 I'm using a table that has implemented a single-linked list (id, parent). This implementation has been working well except recently performance has become unbearable since my lists are getting long and I've been querying nodes individually. I found a promising blog on how to query this in a single query. http://explainextended.com/2009/03/25/sorting-lists/ SELECT @r AS _parent, @r := ( SELECT id FROM t_list WHERE parent = _parent ) AS id FROM ( SELECT @r := 0 ) vars, t_list Only thing is I'm

Radix Sorting with using queue

假装没事ソ 提交于 2020-01-02 02:33:12
问题 I've wanted to create a radix sort implementation using queues. I couldn't figure out which part of my code has problems or which resources should I read. My code may be totally wrong but this is my implementation without any help (I haven't taken a data structures & algorithms course yet). I created a function but it didn't work. While doing research, I saw some code samples but they seemed to be more complex for me. Firstly I wanted to find the least significant digit of all integers Then

Queue performance wise which is better implementation - Array or Linked list

为君一笑 提交于 2020-01-01 03:24:18
问题 Which way gives the faster enqueueing and dequeuing when I have to insert very few elements, Is array better than a linked list? I need to insert few element and I have to remove and read that removed element from queue. If it is array I may have to modify the indexes every time I remove an element. Inserting and deleting may happen simultaneously also. Which one is better from below case? typedef struct{ mylist list; struct mylistQ *next; }mylistQ; Array Code static mylist myListQ[QUEUESIZE

Using insertion sort on a singly linked list

守給你的承諾、 提交于 2020-01-01 00:48:36
问题 So I have an assignment where I'm giving a random list of number and I need to sort them using insertion sort. I must use a singly linked list. I looked around at other posts but none seem to help. I get what insertion sort is but I just don't know how to write it in code. Node* insertion_sort(Node* head) { Node* temp = head_ptr; while((head->n < temp->n) && (temp != NULL)) temp = temp->next; head->next = temp->next; temp->next = head; head->prev = temp; } I dont know if this is right or what

Is the LinkedList in .NET a circular linked list?

我是研究僧i 提交于 2019-12-31 19:19:38
问题 I need a circular linked list, so I am wondering if LinkedList is a circular linked list? 回答1: No. It is a doubly linked list, but not a circular linked list. See MSDN for details on this. LinkedList<T> makes a good foundation for your own circular linked list, however. But it does have a definite First and Last property, and will not enumerate around these, which a proper circular linked list will. 回答2: A quick solution to using it in a circular fashion, whenever you want to move the "next"

Finding the “Nth node from the end” of a linked list

吃可爱长大的小学妹 提交于 2019-12-31 17:58:13
问题 This seems to be returning the correct answer, but I'm not sure if this is really the best way to go about things. It seems like I'm visiting the first n nodes too many times. Any suggestions? Note that I have to do this with a singly linked list. Node *findNodeFromLast( Node *head, int n ) { Node *currentNode; Node *behindCurrent; currentNode = head; for( int i = 0; i < n; i++ ) { if( currentNode->next ) { currentNode = currentNode->next; } else { return NULL; } } behindCurrent = head; while

Difference in LinkedList, queue vs list

大城市里の小女人 提交于 2019-12-31 08:44:44
问题 What is the difference when creating these two objects Queue<String> test = new LinkedList<String>(); and List<String> test2 = new LinkedList<String>(); What are the actual differences between test and test2 ? Are both of them LinkedList ? Are there performance differences or reasons to use one over the other? 回答1: The two statements you've written each construct a LinkedList<String> object to hold a list of strings, then assign it to a variable. The difference is in the type of the variable.

C adding node to head of linked list

喜欢而已 提交于 2019-12-31 03:34:06
问题 I have created a linked list struct in c struct node{ int value; struct node* next; }; a method to add a node at the start of the list : void addFirst(struct node *list, int value){ struct node *new_node = (struct node*) malloc (sizeof (struct node)); new_node->value = value; new_node->next = list; list = new_node; } I create a list (malloc and everything), then call this method, it adds the new node inside the method but when i get back to my main my old list remains unchanged. Using DDD

Reverse a LinkedList c++ [duplicate]

眉间皱痕 提交于 2019-12-31 03:01:11
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Unable to reverse a linked list I'm trying to reverse a linked list: void LinkedList::reverseList() { Node *next=_head; Node *prev=0; while(next!=0) { Node *tmp=next->_next; next->_next=prev; prev=next; next=tmp; } } Lets say the list is: 4->3->2->1 When I print the list, I only see 1 (The print function is good). Any help? Thanks 回答1: Since you said you wanted to find the problem on your own, I'll just give you

Haskell/GHC performance of `any`/`all`

妖精的绣舞 提交于 2019-12-31 00:56:45
问题 I wrote quantification functions exists , forall , and none for Haskell's build-in [] list data type. On multiple occasions, these seemed to prove much more efficient than Prelude / Data.List s any and all . I naively suspect that this performance is due to any and all being implemented using Θ(n) folds. Since I am relatively new to Haskell, I think I must be mistaken, or that there would be a good reason for this phenomenon. From Data.Foldable : -- | Determines whether any element of the