linked-list

Proof of detecting the start of cycle in linked list

From several posts inside stackoverflow and outside, I have come to know how to detect cycles in a linked list, the length of a cycle. I also found the method on how to detect the start of the loop. Here are the steps again for reference. Detecting Loop: Have two pointers, classically called hare and tortoise. Move hare by 2 steps an...

Swap nodes in a double linked list - slow sorting algorithm drops nodes

For practice, I've been working on a compressor which does the find-repeated-parts, make-dictionary, compress-with-huffman codes thing. It's not really working. One of the problems is, for some reason my sorting algorithm drops keywords from the dictionary. I think the problem is in the swap routine, but I'm not sure. ( this routine ...

What is the point of PHP's SplDoublyLinkedList class, and more importantly, Linked Lists in general?

On a quest to expand my programming prowess, I've delved ever-so-slightly into The Standard PHP Library. This led to my discovery of the SplDoublyLinkedList class. From there I read the descriptions of Linked Lists and Doubly Linked Lists on Wikipedia. I understand how they work... But I cannot conceive of a reason WHY we need itor b...

Print union of two linklist without modify them and change append()

/*Task: Two ordered linklist contain number. eg.1->2->3-> and 2->3->5 **Print** union of them eg.1->2->3->5 ,remove duplication, can't change linklist Problem : 1. append() might need to be modified. 2. dnot't know how to use append() to complete the task. */ #include <stdio.h> #include <malloc.h> #include <s...

creating a linked list using Cuda

is it possible to create a linked list on a gpu using cuda? I am trying to do this and i am finding some dificulties. If i can't allocate dynamic memory in a cuda kernel, then how can i create a new nod and add it to the linked list? ...

How do I turn my custom linked list into an array?

I have to implement a method: E[] toArray(E[] a) // Pass an array, convert to singly linked list, then return the array. from java.util Interface List<E> As I mentioned, I have to pass an array, convert it to a singly linked list, sort it, then return the array. In the Node class I have this to work with: public Node(E v, Node<...

Removal of items with duplicate data.

Hi I'm writing a function that removes the consecutive items with duplicate data . e.g For example, passing in the list ->a->b->c->c->a->b->b->b->a->null should result in ->a->b->c->a->b->a->null The list item definition and function declaration are given below struct litem { char data; litem* next; }; Mo code lo...

How to compare 2 objects of generic type

Is there a way to compare two objects that are generic? I'm supposed to find the largest object in a linked list. My first guess was to use the Object's class compareTo method, but I couldn't get that to work. Thanks ...

insert to sorted position linked list

Hello, I have question quite much related to this one I asked a while ago http://stackoverflow.com/questions/3743764/place-a-value-in-the-sorted-position-immediately I wonder if you can use the same approach in that you step backward in a linked list to find the position it should be inserted into. If it is possible how do you loop a ...

Finding duplicates in sorted, linked list.

Hello! I've created a sorted linked list and now I'm trying to figure out how to remove duplicates. I wanted to add code that would do this in the Add method I created but I can't seem to figure it out. I feel like this should be relatively easy but I'm a bit brain dead right now. In my add method I check the index to see where an item ...

C# linked lists

Hey, very basic question, but is there any ToArray-like function for c# linked lists that would return an array of only part of the elements in the linkedlist. e.g.: let's say my list has 50 items and I need an array of only the first 20. I really want to avoid for loops. Thanks, PM ...

Doubly linked lists in C++

What is a doubly linked list? If someone could provide some C++ code to help explain then that would be much appreciated. ...

does systemverilog support linked lists?

I tried implementing a circular doubly-linked list class (with a single sentinel node) in systemverilog. The list itself seems to work as expected but ends up crashing the simulator (corrupting stack?) This led me to wonder if this is something fundamentally unsupported by the language (in terms of allocation)? SV does have a "queue" c...

Why am i getting "warning: assignment from incompatible pointer type"? Double linked list in a struct array

Hi, I'm trying to make an implementation of a double linked list which connects to an array. The struct that makes the array contains the list's Head and Tail pointer. typedef struct myStruct{ int code; struct myStruct *Head; struct myStruct *Tail; }myStruct; myStruct MyArray[10]; Here's my double linked list: struct myList { ...

Build the list {1,2,3} with the minimum assignment statements in C

Rewrite this to minimize the assignment statements /* Build the list {1, 2, 3} in the heap and store its head pointer in a local stack variable. Returns the head pointer to the caller. */ struct node* BuildOneTwoThree() { struct node* head = NULL; struct node* second = NULL; struct node* third = NULL; head = malloc(sizeof(struct node...

C++ - Stack Pop() Function with Singly Linked list

For starters this is apart of my current homework assignment for my Data Structures class. I am not asking for answers, I am asking for help. I have a stack class that is implementing a Linked List instead of an array. I am currently trying to write my pop() function. I have a node for my theBack part of the stack. I am just confused a...