linked-list

Adding custom structure to GSList with Glib

北城余情 提交于 2019-12-24 05:46:08
问题 I'm trying to add a structure to a singly linked list with the function g_slist_append(list, &structure). This seems to work (it's adding the pointer), however I can't seem to find a way to view the elements in the structure when reading the linked list. My structure looks like this: struct customstruct { int var1; int var2; char *string_1; } Then, I make a list: GSList *list = NULL; Then, I append one instance of the structure like this: struct customstruct list_entry; list_entry.var1 = 1;

Menu driven program in c to perform various operations on a linked list

送分小仙女□ 提交于 2019-12-24 04:13:30
问题 The following code works fine for all the functions except the deleteEnd function. When i execute the program all the functions perform the tasks they are supposed to but the deleteEnd function does nothing. There is no change in the linked list on executing the deleteEnd function. Please Help!!!! #include<stdio.h> #include<conio.h> struct node{ int data; struct node *link; }*head = NULL, *new_node, *ptr=NULL, *prev_ptr, *temp; void insertBeg(){ int info; new_node = (struct node*)malloc

Using C++ templates in Linked Lists, with multiple different types appearing in the list

纵然是瞬间 提交于 2019-12-24 03:41:19
问题 (Firstly, as a disclaimer, this is related to an assignment. I'm not asking anyone to do my assignment for me, just to try and help me understand how to implement templates properly.) My current setup is: I have class A, which is a base class. Class B, C and D all children of Class A. I'm trying to make a linked list that, within a single list, can point to either B, C or D. What I currently have setup is something like this: enum Types { TypeB, TypeC, TypeD } struct Node { void *

How do I keep a mutable reference to the last node while building a linked list?

若如初见. 提交于 2019-12-24 03:32:14
问题 I'm trying to implement building a singly-linked list from an Iterator , keeping the order of elements. The structure is defined as: #[derive(Debug)] struct List<T> { list: Node<T>, } type Node<T> = Option<Box<Link<T>>>; #[derive(Debug)] struct Link<T> { head: T, tail: Node<T>, } I was thinking of keeping a mutable reference to the end of the list and expanding it while iterating. However, I couldn't figure out how this could be done. The (non-working) idea was: impl<T> List<T> { pub fn from

hybrid linked list constructed on unordered_map?

有些话、适合烂在心里 提交于 2019-12-24 03:16:28
问题 Hi I wonder if I can set up another linked struct myself to actually set up my own order between keys in the unordered_map? or there is a standard library? I need the fast look up function of unordered_map... For example: #include<string> #include<tr1/unordered_map> struct linker { string *pt; string *child1; string *child2; }; unordered_map<string,int> map({{"aaa",1},{"bbb",2},{"ccc",3},{"ddd",4}}); linker node1 = new linker; node1.pt = &map.find("aaa")->first; node1.child1 = &map.find("ccc"

Handwritten linked list is segfaulting and I don't understand why

瘦欲@ 提交于 2019-12-24 02:09:12
问题 Hi I was working on a bit of fun, making an interface to run gnuplot from within c++, and for some reason the my linked list implementation fails. The code below fails on the line plots->append(&plot) . Stepping through the code I discovered that for some reason the destructor ~John() is called immediately after the constructor John() , and I cannot seem to figure out why. The code included below is a stripped down version operating only on Plot* . Originally I made the linked list as a

Any implementation of an Unrolled Linked List in C#?

情到浓时终转凉″ 提交于 2019-12-24 01:08:39
问题 I'm interested in using an "unrolled linked list" in my C# application. Is anyone aware of a stable implementation, especially one that will allow me to configure how much padding to allocate per array? 回答1: According to the 2nd comment in your own link, such a list should be implemented in BigList in the PowerCollections library. It's open source, so you could have a look at the code and see if it allows for your scenario, or if it can be adapted to fit your needs easily. Other than that, I

Java ArrayList and LinkedList - adding element at end implementation details

时间秒杀一切 提交于 2019-12-24 01:00:01
问题 My understanding of why arraylist is faster than a linkedlist is that with an arraylist you basically only need one action - update the reference at the end array element, whereas with a linked list you have to do much more e.g. create a new node, update 2 references, go through linked list and update the last node to point to the new one etc. However I am not sure how java implement these. How does the arraylist know where the "last" element is, does it store a value of the last element or

How to correctly and safely free() all memory used a nested struct in C?

余生颓废 提交于 2019-12-23 23:51:08
问题 I have four different layers of struct nested. The code is as follows: typedef struct System system; typedef struct College college; typedef struct Student student; typedef struct Family family; #define MAX_COLLEGES 10 #define MAX_NAME_LEN 32 #define MAX_STUDENTS 10 struct System { college *Colleges[MAX_COLLEGES]; }; struct College { char name[MAX_NAME_LEN]; student *Students[MAX_STUDENTS]; }; struct Student { char name[MAX_NAME_LEN]; int id; family *fam; //was typo familiy }; struct Family {

Adding and sorting a linked list in C

我的未来我决定 提交于 2019-12-23 22:52:27
问题 In my assignment, I have to write a function that takes as arguments a pointer to a "LNode" structure and an integer argument. Then, I have to not only add that integer into the linked list, but also put place it so that the list is in proper ascending order. I've tried several various attempts at this, and this is my code as of posting. LNode* AddItem(LNode *headPtr, int newItem) { auto LNode *ptr = headPtr; ptr = malloc(sizeof(LNode)); if (headPtr == NULL) { ptr->value = newItem; ptr->next