linked-list

C/C++ Linked list

I'm trying to make linked list similar too the one here: http://stackoverflow.com/questions/982388/linked-list That is to have the "head", I called it first, inside another struct. However I found doing that change. Makes it hard to add values to the list_item struct. I have tried some few things to see if it works. It compiles, howeve...

Is it any way to implement a linked list with indexed access too?

I'm in the need of sort of a linked list structure, but if it had indexed access too it would be great. Is it any way to accomplish that? EDIT: I'm writing in C, but it may be for any language. ...

Best Possible algorithm to check if two linked lists are merging at any point? If so, where?

Hello, This is an interview question for which I don't have an answer. Given Two lists, You cannot change list and you dont know the length. Give best possible algorithm to: Check if two lists are merging at any point? If merging, at what point they are merging? If I allow you to change the list how would you modify your algorithm? ...

Why does this C code print only the first & last node entered?

#include <stdio.h> #include <stdlib.h> typedef struct { char *Name; int grade; int cost; }Hotel; /*This is data element in each node*/ typedef struct hinfo { Hotel h; struct hinfo *next; }Hinfo; /*This is a single node*/ typedef struct { Hinfo *next; /*This is the head pointer of the linked list*/ }HotelHead; void c...

C++ inheritance designing a linked list

I wanted to make a linked list class ListList that inherits from a class List. ListList uses functions from List, but has its own functions. It has its own start pointer that points to the beginning of the list, and its own Node struct that holds a different amount of elements. But, it looks like, when one of List's functions are called...

Doubly Linked List in a Purely Functional Programming Language

How does one go about doing doubly linked lists in a pure functional language? That is, something like Haskell where you're not in a Monad so you don't have mutation. Is it possible? (Singly linked list is obviously pretty easy). ...

Exchange two nodes in LinkedList

Hello I encountered a simple "problem": Exchange two nodes in a LinkedList (.NET 2) How can I do it in a "optimal" way. Thanks! Dim label1 As New Label() Dim label2 As New Label() '... some code Dim testList As New LinkedList(Of Label) '... some code Dim node1 As LinkedListNode(Of Label) = testList.Find(label1) Dim node2 As LinkedListN...

C++ Linked list destroy function

Hi again, this is kinda a continue of my last question about linked list. I have worked a little more on it and I got stuck at some functions I need to implement. The one I have question on right now is the destroy() function. It is supposed to release memory of every list_ item . The approach is to remove every list_item recursivly fr...

C++ Linked list copy and clone function

Hi,this is also a continuation from my linked list questions I did not get the answer regarding delete. When delete is called is the actual value deleted or is it just the pointer to it? For my question this time is about the clone() and list_copy() functions. What I want to do with those function is to; first call the list _copy() t...

Manually sorting a linked list in Java (lexically)

I am implementing my own linked list in Java. The node class merely has a string field called "name" and a node called "link". Right now I have a test driver class that only inserts several names sequentially. Now, I am trying to write a sorting method to order the nodes alphabetically, but am having a bit of trouble with it. I found...

Deleting node from linked list in C

Okay this is my code for deleting a node from a linked list. vec_store holds seq and size. Variable seq holds the vectors and a pointer. For some reason, the else if(i<s->size-1) doesn't work which is the last condition. Any1 can solve the problem? By the way this is C code. void delete_vec(vec_store s, int i) { if (i<0 || s->si...

Inserting a node into a linked list c

Okay This is the code for insering a node into a linked list. vec_store holds seq and size. Variable seq holds the vectors and a pointer. and vec_mag takes magnitude of vectors. For some reason, the (vec_mag(v)<=vec_mag(temp2->next->data)) doesn't work which is the last condition. Any1 can solve the problem? By the way this is C code...

Java Linked List Question

Hello, Using a Comparator and Iterator, I am trying to add objects into a linked list in order. So far, I have the following: public class ComparatorClass implements Comparator<Integer> { public int compare(Integer int1, Integer int2) { return int1.compareTo(int2); } } and: import java.util.ArrayList; import java.util.C...

Double Linked Lists in C++

NOTE: THIS IS FOR HOMEWORK SO PLEASE DO NOT INCLUDE BLOCKS OF CODE IN YOUR ANSWERS I have an assignment that requires us to implement a doubly linked list class. For some reason they defined the node struct as follows: struct node { node *next; node *prev; T *o; }; It seems to me that it would be a lot easier to write ...

free of doubly linked list

I am using a doubly linked list in a C program. I am getting confused about freeing the memory. Should I free the list node by node? Or, by assigning head and tail nodes to NULL? ...

Comparing chararrays in linked list in the C programming language.

How do you compare and sort chararrays in a linked list, cant you compare like this 'Smith' > 'Andersson' ? struct person { char name[20]; struct person *nextPerson; }; . void createNode(PersonPtr *sPtr, struct person t[]){ PersonPtr newPtr; /* pointer to new node */ PersonPtr previousPtr; /* pointer to previus node in list */ P...

merged linked list in C

Hello, This question was asked to me in an interview: There are two header of two linked lists. There is a merged linked list in c where in the second linked list is merged into the first one at some point. How could we identify the merging point and what is the complexity of finding that point ? Could anybody please help? ...

Why does my inputchar function keep looping?

#include <iostream> using namespace std; struct Node { char item; Node *next; }; void inputChar ( Node * ); void printList (Node *); char c; int main() { Node *head; head = NULL; c = getchar(); if ( c != '.' ) { head = new Node; head->item = c; inputChar(head); } printList(head); ...

How can I use iteration instead of recursion to input values into a linked list?

Ok so let's say we have a linked list of characters with a head pointer. How can I create a loop to enter a string of characters into the linked list? My problem is when I think of head and head->next and head->next->next . . . it only seems natural to use a recursive function to set the characters at each node. ...

2D LinkedList.contains() in Java

Hey, everyone. I'm new to Java and I have 2D LinkedList like this: LinkedList<LinkedList<String>> albums = new LinkedList<LinkedList<String>>(); Which is filled with data like so: if (!artist.isEmpty() && !name.isEmpty()) { albums.add(new LinkedList<String>()); albums.getLast().add(artist.toString()); albums.getLast()...