linked-list

implement linked list using array - advantages & disadvantages

£可爱£侵袭症+ 提交于 2019-12-28 16:05:47
问题 I know how to implement linked list using array. For example we define a struct as follow: struct Node{ int data; int link; } "data" stores the info and "link" stores the index in the array of next node. Can anybody tell me what is the advantage and disadvantage of implementing a linked list using array compared to "ordinary" linked list? Any suggestion will be appreciated. 回答1: If you back a linked list with an array, you'll end up with the disadvantages of both . Consequently, this is

Initialization discards qualifiers from pointer target type

女生的网名这么多〃 提交于 2019-12-28 13:41:07
问题 I'm trying to print the list of a singly linked list that I referred to in link text. It works, but I do get the compiler warnings: Initialization discards qualifiers from pointer target type (on declaration of start = head) and return discards qualifiers from pointer target type (on return statement) in this code: /* Prints singly linked list and returns head pointer */ LIST *PrintList(const LIST *head) { LIST *start = head; for (; start != NULL; start = start->next) printf("%15s %d ea\n",

Deleting a node from linked list in C

▼魔方 西西 提交于 2019-12-28 07:04:34
问题 My problem is deleting a node from linked list. I have two structs : typedef struct inner_list { int count; char word[100]; inner_list*next; } inner_list; typedef struct outer_list { char word [100]; inner_list * head; int count; outer_list * next; } outer_list; My problem is in deleting a node from outer_list linked list. For example when user entered aaa to delete, delete function should find the node with outer_list->word = aaa and delete this node and reconnect the list again . I tried

Is there a known implementation of an indexed linked list?

随声附和 提交于 2019-12-28 05:46:13
问题 My gut tells me there is no good way to achieve this, but, unlike Mr. Stephen Colbert, I'd rather trust a community of developers than my gut... Is there a known way to efficiently implement a "best of both worlds" list, one that provides random access by index and O(1) insertion/removal like a linked list? I foresee two possible outcomes: either "No, this is impossible, for the following obvious reasons..." or "Uh, yes, this has been done; see here, here, and here." 回答1: I don't believe it

Using pointers to remove item from singly-linked list

白昼怎懂夜的黑 提交于 2019-12-27 11:09:25
问题 In a recent Slashdot Interview Linus Torvalds gave an example of how some people use pointers in a way that indicates they don't really understand how to use them correctly. Unfortunately, since I'm one of the people he's talking about, I also failed to understand his example: I've seen too many people who delete a singly-linked list entry by keeping track of the "prev" entry, and then to delete the entry, doing something like if (prev) prev->next = entry->next; else list_head = entry->next;

When should I use a List vs a LinkedList

旧巷老猫 提交于 2019-12-27 09:03:05
问题 When is it better to use a List vs a LinkedList? 回答1: Edit Please read the comments to this answer. People claim I did not do proper tests. I agree this should not be an accepted answer. As I was learning I did some tests and felt like sharing them. Original answer... I found interesting results: // Temporary class to show the example class Temp { public decimal A, B, C, D; public Temp(decimal a, decimal b, decimal c, decimal d) { A = a; B = b; C = c; D = d; } } Linked list (3.9 seconds)

When should I use a List vs a LinkedList

血红的双手。 提交于 2019-12-27 09:01:31
问题 When is it better to use a List vs a LinkedList? 回答1: Edit Please read the comments to this answer. People claim I did not do proper tests. I agree this should not be an accepted answer. As I was learning I did some tests and felt like sharing them. Original answer... I found interesting results: // Temporary class to show the example class Temp { public decimal A, B, C, D; public Temp(decimal a, decimal b, decimal c, decimal d) { A = a; B = b; C = c; D = d; } } Linked list (3.9 seconds)

want to read more than 50,000 txt files and save them in linked list in C++

假装没事ソ 提交于 2019-12-26 15:07:56
问题 #include<iostream> #include<windows.h> #include<string> #include<fstream> using namespace std; class linklist //linked list class { struct main_node; struct sub_node; struct main_node // main node that only have head pointers in it { sub_node *head; main_node() { head=NULL; } }; main_node array[26]; struct sub_node { double frequency; string word; sub_node *next; sub_node() { frequency=1; word=""; next=NULL; } }; public: void add_node(string phrase) { char alphabat1=phrase[0]; if(isupper

want to read more than 50,000 txt files and save them in linked list in C++

此生再无相见时 提交于 2019-12-26 15:06:47
问题 #include<iostream> #include<windows.h> #include<string> #include<fstream> using namespace std; class linklist //linked list class { struct main_node; struct sub_node; struct main_node // main node that only have head pointers in it { sub_node *head; main_node() { head=NULL; } }; main_node array[26]; struct sub_node { double frequency; string word; sub_node *next; sub_node() { frequency=1; word=""; next=NULL; } }; public: void add_node(string phrase) { char alphabat1=phrase[0]; if(isupper

Checking if an object is contained within a linkedlist

久未见 提交于 2019-12-26 15:06:14
问题 I have this program and in the main method I add a value into a linked list. When I try to add another value through a method that checks to see if the value added previously is in the list, it does not recognize the value as being in the list and does the operation it should do if it is not in the list. Why is this program not recognizing the objects that are put into the list? the program does not recognize "h" has been added to the list. import java.util.LinkedList; import java.util.List;