linked-list

Linked List Losing nodes after leaving recursive function

struct Letter { char let; Letter *next; }; Please look at the function below called addLETTERS(). int main() { Letter *Top = 0; Letter *head = 0; char letters = 'a'; head = new Letter; Top = new Letter; MakeNull(head); MakeNull(Top); addLETTERS(Top, head,letters); retur...

What is the proper way of handling linked lists in wxWidgets?

I wrote an application using wxWidgets that uses wxList. I am having some random crahses (segfault) in the destructors that collect the list data. I could not find a definite way of removing items from the list (Erase() VS DeleteNode()). Even iterating over the items has two flavours (list->GetFirst() VS list->begin()). Below is a test ...

C 2D linked list

So i have struct node { int number; struct node *next; struct deck{ int number; struct deck *next; }; }; I want to create a 2D linked list. How can i initialize something like this? Thanks. ...

Linked Lists in C without malloc

#include <stdio.h> typedef struct node { int i; struct node *next; }node; node getnode(int a) { struct node n; n.i=a; n.next=NULL; return n; } main() { int i; node newtemp,root,temp; scanf("%d",&i); root=getnode(i); temp=root; while(i--) { newtemp=getnod...

Did anyone else get a deeper understanding about pointers when learning linked lists?

I'm a student at the University and I'm taking the Data Structures class. When learning linked lists and doubly linked lists, did you guys feel you learned a deeper understanding of pointers, dynamic memory allocation, and memory usage? I just created my first linked list(it was actually a doubly linked list) and it seemed to me like a ...

C - Copy string into a linked list variable

#define STRLEN 65 /*Create linked list */ struct node { char str[STRLEN]; struct node *next; }; newInput = malloc(sizeof(struct node)); strcpy(newStr, newInput->str); I left the other parts of the code, but it doesnt seem to be copying the string into newInput->str. The string accepted is only 64 bytes. It's just blank when...

Linked list in C, no member error

I am trying to write a database for class in which I read all the key values in from a file (formatted keyNULL BYTEvalueNULL BYTE etc). I amt rying to use a linked list for this, but I get the error that the struct has no next value. Please help me! #include <stdio.h> #include <stdlib.h> #include <assert.h> #include <string.h> #include ...

Passing a object by reference in c++

This is a noobie question, but I'm not sure how to pass by reference in C++. I have the following class which sets up a Node and a few functions. class Node { public: Node *next; int data; Node(int dat) { next = NULL; data = dat; } Node* getNext() { return next; } void setNext(Node *n) {...

LinkedList, First and Last

I have a question about LinkedList<>. There are properties of this list First and Last. Will that properties correct if I will set Last.AddNext(First)? I need to have a list where Last>Next = First, but identify clearly the First and Last elements. I have a cycle process.NextStep, NextStep, but need to be able to identify each Step (p...

Linked list in Pascal

Hi, Im looking for a good and simple implementation of a linked list in Pascal. As Im a Pascal beginner it would help me alot as a study material. Thanks for any tips. ...

Is time complexity for insertion/deletion in a doubly linked list of order O(n)?

To insert/delete a node with a particular value in DLL (doubly linked list) entire list need to be traversed to find the location hence these operations should be O(n). If that's the case then how come STL list (most likely implemented using DLL) is able to provide these operations in constant time? Thanks everyone for making it clear ...

Linked list insertion sort

I'm not very advanced in the sorting part of programming yet, so I was looking for some help with my algorithm. void sortList() { Item_PTR tmpNxt = current->nextItem; Item_PTR tmpPTR = current; int a, tmp; while(tmpNxt != NULL) { a = tmpPTR->value; while(tmpNxt != tmpPTR && tmpNxt->value < a) ...

how to find number of nodes in loop of linked list?

how to find the number of nodes in a loop of linked list? for e.g A ----> B ----> C -----> D -----> E Λ | | | | V H <----- G <----- F Find the number of nodes in a loop from C to H Fundamental problem is how to find poin...

How is Python's List Implemented?

Is it a linked list, an array? I searched around and only found people guessing. My C knowledge isn't good enough to look at the source code. ...

Quickly searching a doubly linked list

Hi, I currently have a simple database program that reads keys in from a text file and stores them in a doubly linked list (values are read later if they are required). Currently, I do a sequential search on the list, but that is clearly rather slow. I was hoping that there is another way to do. I was reading about binary trees (in parti...

Inserting node in a double-linked list

I'm having trouble understanding the second half of connecting a new node into a double-linked list. I'm writing an add method that takes in the node which the new node is to be inserted after. My area of difficulty is understanding how to link to the next node after the previous node links have been re-directed to the new node. So, h...

Linked list error

I have an error and a warning while trying to compile my linked list implementation in c warning: assignment from incompatible pointer type error: dereferencing pointer to incomplete type here is the list.h #ifndef LIST_H #define LIST_H #include <stdio.h> typedef struct _ListElmt{ void *data; struct ListElmt...

size of linked list in c++ function

Can someone please tell what is the code for checking the size of a linked list(number of nodes).This is what my code is(inserting nd deleting head + printing info of all nodes) struct node { int info; node *nextptr; }; class list { private: node *L,*tail; int count; public: list() { L=tail=NULL; ...

How to add node at some specific index in a linked list?

void insertLoc(int n, int i) inserts a node with info n after the ith location in the list. If the ith location does not exist in the list then the program should exit with an error message. Can anyone help me with the code please... #include<iostream> #include<process.h> using namespace std; struct node { int info; node *n...

Array of Linked lists on disk

I am trying to find how to store and process (search, add, remove) an array of linked lists on disk. For example in memory, it would like struct list { int a; struct list *next; }LIST LIST *array[ARRAY_SIZE] int main{ ... LIST *foo = array[pointer]; /* Search */ while(foo!=NULL){ ... foo=foo->next } } I believe that by ...