linked-list

Doubly linked, cyclic list in standard library

纵饮孤独 提交于 2019-12-11 08:19:32
问题 I need doubly linked cyclic list, but a cant find it in STL containers (singly linked cyclic list too). It may looks like that: element 0 <-> element 1 <-> ... <-> ... ^ ^ | | v v element n <-> element n-1 <-> element n-2 Can you show me what i missed? Thanks in advance. 回答1: You haven't missed anything. There is no such container in the standard library. 来源: https://stackoverflow.com/questions/21649295/doubly-linked-cyclic-list-in-standard-library

unable to modify global variable in c

好久不见. 提交于 2019-12-11 07:50:35
问题 I'm learning C, and in this program I'm trying to implement a simple linked list. Each node of the list contains an integer, and a pointer to the next node. Pointer head points to the first node in the list, but initially the list is empty, so I initialized head = NULL . I want to do two operations on the list - populate it, and print it. To populate the list, I'm calling function insert_node with two arguments: head , and the integer I want to insert. The problem is I need the function

Program received signal SIGSEGV, Segmentation fault. C++ LIST

杀马特。学长 韩版系。学妹 提交于 2019-12-11 07:35:07
问题 L.insert() gives segmentation fault if I call it after L.deleteElement() . This is the error message: 196 nPtr = (nodePtr)malloc(sizeof(node)); (gdb) print(c) $7 = 2 (gdb) next 197 if(nPtr!=NULL){ (gdb) print(nPtr) $8 = (nodePtr) 0x615c70 (gdb) next 198 nPtr->data = element; (gdb) print(element) $9 = "(" (gdb) next Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7b74413 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11:

Properly removing elements from linked-list? Memory errors with pointers

别来无恙 提交于 2019-12-11 07:32:36
问题 I'm implementing a hashtable that has a remove_entry function as well as a clear_table function. Right now I'm getting memory read errors pertaining to the remove_entry function. And help would be greatly appreciated These are my structures: typedef struct bucket { char *key; void *value; struct bucket *next; } Bucket; typedef struct { int key_count; int table_size; void (*free_value)(void *); Bucket **buckets; } Table; Here's my function: int remove_entry(Table * table, const char *key){

How to point an array inside a dynamic array to something?

时光毁灭记忆、已成空白 提交于 2019-12-11 07:13:50
问题 I have a struct like this: struct Key_Node { int key; struct Package_Node *next_package; }; I will create a dynamic array " struct Key_Node arrayMain[X] " where the value of X will be entered by the user and depending on it I will create the dynamic array. Since I don't know the size of the array, obviously I can not point each pointer of the dynamic array to something. So what will I have to do here? I have another struct that looks like this. struct Package_Node { int bar_code; float

C++ Circular Linked List : remove element

情到浓时终转凉″ 提交于 2019-12-11 07:13:18
问题 I am done with insertion, search in circular linked list but for removal I am getting compiler errors... Following is my structure for nodes. struct node { int p_data; struct node* p_next; node(node* head, int data) { p_next = head; p_data = data; } explicit node(int data) { p_next = nullptr; p_data = data; } }; node* remove_circular(node* head, node* target) { if (head == target->p_next) { delete head; return nullptr; } auto next_pointer = target->p_next; target->p_data = next_pointer->p

How to implement an XOR Linked List in Python?

 ̄綄美尐妖づ 提交于 2019-12-11 07:06:00
问题 Given that python objects are only a reference to the actual memory Objects and memory address of objects cannot be retrived. Is it possible to implement an XOR linked list in Python ? if yes how ? 回答1: You can't build an XOR linked list in Python, since Python doesn't let you mess with the bits in pointers. You don't want to implement that anyway -- it's a dirty trick that makes your code hard to understand for little benefit. If you're worried about memory, it's almost always better to use

Inserting a node before a given node in doubly linked list

泪湿孤枕 提交于 2019-12-11 06:49:00
问题 I am trying to insert a node before a given node. But I am not able to get the required output. #include<stdio.h> #include<stdlib.h> struct node{ int data; struct node* prev; struct node* next; }; void insert_beg(struct node** head, int new_data){ struct node* temp = (struct node*)malloc(sizeof(struct node)); temp->data = new_data; if(*head == NULL){ temp->next = *head; temp->prev = NULL; *head = temp; } else{ temp->next = *head; (*head)->prev = temp; *head = temp; } } void insert_before

How to delete a specific node in a linked list

两盒软妹~` 提交于 2019-12-11 06:48:40
问题 I previously needed help debugging my deleteNode method. It works now (updated version posted below) but I want it to provide for the case when it has to delete the head node. At the moment, it returns a NullPointerException where I've inserted * in deleteNode. I don't know how any of my variables can be null at that point, seeing as my while loop requires both position and head to not be null in the first place. public class LinkedList { private class Node { int item; Node link;

Cython implementation no faster than pure python

天大地大妈咪最大 提交于 2019-12-11 06:46:41
问题 For an exercise I've written a XOR doubly-linked list %%cython from cpython.object cimport PyObject from cpython.ref cimport Py_XINCREF, Py_XDECREF from libc.stdint cimport uintptr_t cdef class Node: cdef uintptr_t _prev_xor_next cdef object val def __init__(self, object val, uintptr_t prev_xor_next=0): self._prev_xor_next=prev_xor_next self.val=val @property def prev_xor_next(self): return self._prev_xor_next @prev_xor_next.setter def prev_xor_next(self, uintptr_t p): self._prev_xor_next=p