linked-list

invalid use of template name without an argument list

。_饼干妹妹 提交于 2020-02-26 05:52:07
问题 I am facing a problem with my linked list class, I have created the interface and implementation files of the class, but when I build it, this error occurs: "invalid use of template name 'LinkedList' without an argument list". here's my interface file: #ifndef LINKEDLIST_H #define LINKEDLIST_H template <typename T> struct Node{ T info; Node<T> *next; }; template <typename T> class LinkedList { Node<T> *start; Node<T> *current; public: LinkedList(); ~LinkedList(); }; #endif // LINKEDLIST_H and

Swapping nodes in double linked list

痴心易碎 提交于 2020-02-21 03:04:53
问题 I'm trying to implement a function that swap two nodes of my double linked list, in order to sort the content of the current directory. But my function seems to 'delete' some elements of my list, here is the code : void node_swap(struct s_node *left, struct s_node *right) { struct s_node *tmp; tmp = left->prev; if (tmp) { tmp->next = right; right->prev = tmp; } else right->prev = NULL; left->prev = right; left->next = right->next; right->next = left; right->next->prev = left->prev; } I can't

Why do we need to detect a loop in a linked list

╄→尐↘猪︶ㄣ 提交于 2020-02-15 12:33:33
问题 I see many Q/A on how to detect a loop in linked list, but I want to understand is why we want to do that, in other words what are the practical use cases of detecting a loop in a linked list 回答1: In real life, you'll probably never need to detect a loop in a linked list, BUT the algorithms for doing that are important and I have used them in real life many times. Pretty often, for example, I will process a linked data structure recursively when it's supposed to be tree-shaped. If it isn't

Why do we need to detect a loop in a linked list

亡梦爱人 提交于 2020-02-15 12:31:01
问题 I see many Q/A on how to detect a loop in linked list, but I want to understand is why we want to do that, in other words what are the practical use cases of detecting a loop in a linked list 回答1: In real life, you'll probably never need to detect a loop in a linked list, BUT the algorithms for doing that are important and I have used them in real life many times. Pretty often, for example, I will process a linked data structure recursively when it's supposed to be tree-shaped. If it isn't

Can you create an array of linked lists in Java?

北慕城南 提交于 2020-02-05 04:40:09
问题 Is it possible to create an array of linked lists? Or an arraylist of linked lists? I've been searching everywhere and seem to be getting contradicting answers. I've seen "no" answers that state that it can't be done because you can't make an array of things that can be dereferenced. I've seen "yes" answers that state it can be done and they end there. Thanks in advance. 回答1: If I understand you right, you basicly want to make a 2D Array, but with the second half being a linked list. import

Linked lists - single or double pointer to the head

人走茶凉 提交于 2020-01-30 02:55:29
问题 We are given a task and a struct of linked list: typedef struct dlistint_s { int n; struct dlistint_s *prev; struct dlistint_s *next; } dlistint_t; And the function with the following prototype: dlistint_t *add_dnodeint(dlistint_t **head, const int n); What are the advantages and why one would be using a double pointer to the head when creating a function? 回答1: The reason to pass pointer to pointer to head is that any modification to the pointer head will be seen in the caller function and

Linked list in C , Can't insert and display node

倖福魔咒の 提交于 2020-01-25 04:30:29
问题 I tried to implement the linked list but couldn't make out what is actually going wrong that it isn't showing the expected result? I tried to trace the control flow of the program by putting in random printfs at suspicious places... I tried to trace the control and realized that after inserting the first node the changes are not getting reflected in the original linked list; after getting back to main() the linked list is empty again! #include<stdio.h> #include<stdlib.h> struct node { int

Converting a list to a linked list

旧街凉风 提交于 2020-01-24 19:35:09
问题 I'm trying to figure out to convert a list to a linked list. I already have a class for the link but I'm trying to figure out how to convert a list to linked list, for example: def list_to_link(lst): """Takes a Python list and returns a Link with the same elements. >>> link = list_to_link([1, 2, 3]) >>> print_link(link) <1 2 3> """ class Link: empty = () def __init__(self, first, rest=empty): assert rest is Link.empty or isinstance(rest, Link) self.first = first self.rest = rest def print

What is expected when I am told “Sort a singly linked list”

心不动则不痛 提交于 2020-01-24 19:02:05
问题 It might be for pedantic purposes but not homework. I have below question about 'Sorting a singly linked list' (Any kind of list for that matter) Assume for this questions we want to sort in ascending order of values in each node. Does this question expect me to just sort the list by swapping the values of each node in the list so that the values are in some order(ascending/descending). Here the original values of nodes (before sorting) would be changed in order to reflect the sorted list.

Making a linked list unique

眉间皱痕 提交于 2020-01-24 08:50:33
问题 So I have the list: 8,9,1,2,3,5,3,1,8,1,4,5,2,7,9,9,5,6 and want to reproduce it as unique (only containing one of the same number) so this one would be 8,9,1,2,3,5,4,7,6 the only issue that is occurring is that the remove() method deletes the first instance of a nodes value and the first occurances of a number are suppose to be kept and following instances are suppose to be deleted from the list. Without collections, hashmaps, or anything. while(current.getPrevious() != null) { while(next