linked-list

How to eliminate duplicates from a linked list of unicode characters, without using any extra memory

“Find a recurring element in a linked list of unicode characters. If a unicode character/s is found to have a duplicate then just delete that repeating node and adjust the list. The constraint was to not to use any extra memory.” My answer: Assuming that the unicode char doesn't include surrogate pair char As I am using c# I don't know...

Trouble in implementing link list sorting in c#

I am having trouble implementing a sort algo (merge) for singly list as defined below My mergesort method always gives me null..I am not able to figure out what is wrong Can you guys help me out? Node class public class Node { private int data; private Node next; } Linked List class public class ...

Moving items in linked list C#.NET

I'm trying to move items in my list but when I compare against the last option I exit out before I move the items in my move linked list. Is there a way to do that before the node gets put at the end and can't loop through to move the items? LinkedList<BD> list = new LinkedList<BD>(b[arg].Values); LinkedListNode<BD> node, terminator...

How to write a function that gets a linked list of any node type and frees the memory used by it?

I'm sure some of you already experienced it. I have two linked lists of different types and I have two distinct functions that free the memory used by them. Those two functions are identical except for one thing. Generally a function that frees a list would looks like this: void free_list(T *p) { T *next; /* here */ while (p...

Which data structure best represents this data?

Is this a list of lists or just a bunch of trees(forest)? ...

how to init an iterator

hi folks, i just intent to initialize an iterator over a generic linked list like that (generic typ T seems to be erased in here since the site interpret it as tag) public <T> LinkedList<T> sort(LinkedList<T> list){ Iterator<T> iter = new list.iterator(); ... but i got the error: "list cannot be resolved" what's wrong? ...

Is it OK to use "delete this" to delete the current object?

I'm writing a linked list and I want a struct's destructor (a Node struct) to simply delete itself, and not have any side effects. I want my list's destructor to iteratively call the Node destructor on itself (storing the next node temporarily), like this: //my list class has first and last pointers //and my nodes each have a pointer to...

Garbage Result! C++ LinkedList

Given the code in Main: // main.cpp wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95)); Two things will happen: The winery ctor is invoked where I have intialized the winery private members: //winery.cpp winery::winery(const char * const name, const char * const location, const int acres, const...

What is the Definition of a Lisp Cons Cell?

What exactly is the definition of a Common Lisp Cons Cell? How is a Cons Cell different than a standard linked list item? After all, both the cons cell and the linked list item have a value and a pointer to the next cell or item... or is this understanding wrong? ...

How do you insert into a sorted linked list?

I just need to have a linked list in order by name. I can only get it as far as 1st, 3rd, 5th, .. nodes. I just can't think this far. I want to be a C++ programmer but if I can't understand this is their any hope? STL containers std::lists are not an option for me at this point as a student. What you see in the list function is what I am...

Why I cannot inherit LinkedListNode<T>?

In .NET 3.5, I am using the LinkedList class but I am having the following issue. I want the items of that list to be aware of the previous and next items in the list. In other words, I want the method in the items to be able to do this.Next, this.Previous. Is this possible? Below is an example of what I would like to do. Day d1 = new D...

linked list with no duplicates

I have the following code (correct for my simple tests) for a linked list for no duplicates, but I think it is a bit ugly. Could anyone recommend a cleaner way to handle the duplicate code? The current piece in question is: if( (val == cur->val) || (cur->next && (val == cur->next->val)) ) But I think that a better solution might exi...

MATLAB linked list

What are some possible ways to implement a linked list in MATLAB? Note: I am asking this question for pedagogical value, not practical value. I realize that if you're actually rolling your own linked list in MATLAB, you're probably doing something wrong. However, I'm a TA for a class that is MATLAB-intensive this semester, and my goa...

How do I use linkedlists for java?

I need to use a LinkedList to add cells of a prison with the cell numbers 1.1, 1.2, 1.3, 1.4 etc. There are two levels and odd numbered cells have 1 bunk whereas even numbered cells have 2 bunks. How can I do this? I did this to create a linkedlist. That is in my Cells class and I have 2 child classes which inherit from the Cells class ...

linkedlist which links to itself?

Hi All, Is there a name for a linked list type structure where the head and tail nodes link to each other? In such a list you can obviously iterate through it forever as it double backs on itself. Was just wondering. ...

Reverse a single chained List

Hi. I hope I am using the right terminology. I have made a single-chained list. class MyStack { public Node Initial { get; set; } public MyStack() { Initial = null; } public void Push(int data) { var node = new Node { Data = data, Next = Initial }; Initial = node; } public int ...

Remove node from single linked list.

Hi, as far as I can see, you can do: Find the node to remove. node.previous.next = node.next node.next.previous = node.previous node.previous = null node.next = null Dispose of node if you're in a non-GC environment If your list is a double linked. But how do you do it with a single linked list? I have tried a lot of things, with no...

Count number of nodes in a linked list that may be circular

Here is the problem, it is from Sedgwick's excellent Algorithms in Java (q 3.54) Given a link to a node in a singly linked list that contains no null links (i.e. each node either links to itself or another node in the list) determine the number of different nodes without modifying any of the nodes and using no more than constant memory ...

traversing task_struct->children in linux kernel

I am trying to traverse a task_struct's children in the linux kernel and get information from the children. I'm having problems with all the information, so let's just keep it at the getting the pid for simplicity. This is the relavant part of my code. struct list_head * p; struct task_struct ts, *tsk; pid_t tmp_pid; INIT_LIST_HEAD(&ts...

Visual Explanation Guidance needed for reversal of Linked List datastructure code ?

Hi, I have following piece of code for reversing the linked list. I am getting confused in while loop and so would certainly appreciate if someone can provide visual explanation of how actually it's working. static void Reverse (struct node** headRef) { struct node* result = NULL; struct node* current = *headref; stru...