linked-list

C++ Bubble sorting a Doubly Linked List

I know bubble sort is probably not the fastest way to do this but its acceptable. i'm just having trouble with adjusting the algorithm to double link lists from arrays. My double linked lists have a type int and a type string to hold a number and a word. My list was sorted with an insertion sort that I wrote to sort alphabetically, now ...

What is a good name for an instance method that adds a linked-list node after the target?

I'm creating a doubly-linked list in Objective-C. I would like my node class to include an instance method that allows me to add another node after the target node, like so: // start <-> nodeA <-> nodeB <-> nodeC <-> end Node * newNode = [Node node]; [NodeB thisMethodNeedsAGoodName:newNode]; // start <-> nodeA <-> nodeB <-> newNode <-...

cstring trouble for a beginner

Hi I'm trying to make a program that read a file line by line and then put the readed line into a a linked list, my problem is to add the string to list. Look at the code, in the else test you can see my problem. #include<stdlib.h> #include<stdio.h> struct list_el { char *ord; struct list_el * next; }; typedef struct list_...

Linked list problem

Hiii ... If we are given two linked lists (may be of different length) such that a few nodes from the end are common ... How do we find the first common node in least time as possible ... ? The lists are singly linked . Some nodes are common from the end and we need to find the first common one for both among them FROM THE END. ...

Can I use java.util.LinkedList to construct a circular/cyclic linked list?

I would like to create a circular/cyclic linked list where the tail of the list would point back to the head of the list. So can I use java.util.LinkedList and modify the tail node after creation of the list to make it circular/cyclic? If so, can you show me some code on how that would happen? If I can't use java.util.LinkedList, how sh...

How to convert a binary search tree into a doubly linked list?

Given a binary search tree, i need to convert it into a doubly linked list(by traversing in zig zag order) using only pointers to structures in C++ as follows, Given Tree: 1 | +-------+---------+ | | 2 3 | | +----+---+ ...

Help making a singly linked list in Java

Hi all, This is for homework but please know that I have looked online for help (such as http://www.sethi.org/classes/class_stuff/cis435/others/notes-java/data/collections/lists/simple-linked-list.html) and my textbook but I am still having some issues. Any help would be appreciated... Right now I'm trying to just insert values in but...

linked list memory diagram

struct letter { char ch; struct letter *ptr_next; } *ptr_first,*ptr_this; //ptr this contains the address of the first node and ptr this contains the address of last node added. A word chair has to be inserted in the linked list such that C goes into the first node,h in the second and so on.. The attached picture is the memory diagram ...

When do you know when to use a TreeSet or LinkedList?

What are the advantages of each structure? In my program I will be performing these steps and I was wondering which data structure above I should be using: Taking in an unsorted array and adding them to a sorted structure1. Traversing through sorted data and removing the right one Adding data (never removing) and returning that struct...

What are some uses for linked lists?

Do linked lists have any practical uses at all. Many computer science books compare them to arrays and say the main advantage is that they are mutable. However, most languages provide mutable versions of arrays. So do linked lists have any actual uses in the real world, or are they just part of computer science theory? ...

c2955 error on my Double Link List project

Okay, I'm making a project that implements a Double Linked List using classes, templates and structures. I constantly get the error: doublelinklist.h(21) : error C2955: 'Node' : use of class template requires template argument list when declaring the head and tail of a node in the LinkedList class. DoubleLinkList.h: #ifndef DOUBLEL...

sorting the linked list

I am trying to make a function that sorts the linked list,which sorts the list by names. struct student { char name[50]; int roll_no; struct student *ptr_next; }*ptr_this,*ptr_first;/*ptr first points to first pointer */ void SortRecord(void) { struct student *out,*in,*temp; for(out=ptr_first;out!=(struct student*)NULL;out=out...

Linked list problem

Hello, I got some problem with the linked list I've written. I dunno if it's either my insert function that the problem, or if it's my traverse function that's not correct. I hope for some input. A side note, I'm initalising the list in main now since I don't know if my initNode function is correct. #include <iostream> using namespace ...

I need some help clearing up a problem with sorting a Priority Queue+linked list in Java.

Hello I am trying to implement a Priority Queue in Java from scratch with a linked list but I am having a problem sorting elements on insertion. Here is my program thus far, any help would be massively appreciated. import java.util.Scanner; public class T0 { public static void main(String args[]) { Scanner keyboard = new...

How do I pass a string to a linked list instead of an array of characters in C?

I understand that there's no String data type in C. What I want to do is get an input string from the user and store it to a variable without having to define how many characters it needs to have. Can I do that using linked lists? I want to avoid putting it to a character array as much as possible so linked lists are the only thing I can...

Handling player on turn with Objective C

I'm creating a simple app which has a list of characters and a list of (4) players, the players is simply a reference to a playable character. I'm stuck on how to do the following: Make a reference to the current player on turn Find out who the next player on turn is Handling the last player so that it will return to the first player ...

Creating a very simple linked list

I am trying to create a linked list just to see if I can, and I am having trouble getting my head around it. Does anyone have an example of a very simple implementation of Linked list using C#? All the examples I have found so far are quite overdone. ...

Intrusive list threadsafe - best way

How do you create an intrusive slist (boost) that is threadsafe so that multiple threads can remove items or add items? I'd want fairly fine grained locking; so I can lock only the necessary nodes and not the whole list each time. Do I just write a wrapper class around boost slist or is it better to just implement it myself? ...

Array Performance very similar to LinkedList - What gives!?

So the title is somewhat misleading... I'll keep this simple: I'm comparing these two data structures: An array, whereby it starts at size 1, and for each subsequent addition, there is a realloc() call to expand the memory, and then append the new (malloced) element to the n-1 position. A linked list, whereby I keep track of the head, ...

Segmentation Fault when deleting complete linked list

Hello, I'm trying to delete whole linked list but getting segmentation fault and not able to detect what is the real problem. When I tried debugging using gdb, it is able to remove the first node but throw segmentation fault when deleting second node. Please suggest me what can be the possible reason. #include <iostream> using namespac...