linked-list

Creating an array problem. help please

Dupe: http://stackoverflow.com/questions/185594/java-generics-syntax-for-arrays I want to create an array that will hold linked lists of Integer type.. import java.util.LinkedList; public class Test { public static void main(String [] args){ LinkedList<Integer> [] buckets = new LinkedList<Integer>[10]; } } I ge...

Traverse from end to front ( C++ LL Q:1 )

Hi, int LinkedList::DoStuff() { Node *Current = next_; while ( Current != NULL ) { Current = Current->next_; length_++; } // At the last iteration we have reached the end/tail/last node return length_; } there are no more nodes beyond the last. How can i traverse to the tail-end to the front-head? ...

linked list problem in c: the print function deletes the value from my list

As a part of an assignment, I need to write two functions: a function that sums up two natural numbers represented as a linked list a functions that prints a number represented in the same way. for some reason, both function work perfectly fine separately, but when I try to use the print function on the result of the sum function, i...

Why is inserting in the middle of a linked list O(1)?

According to the Wikipedia article on linked lists, inserting in the middle of a linked list is considered O(1). I would think it would be O(n). Wouldn't you need to locate the node which could be near the end of the list? Does this analysis not account for the finding of the node operation (though it is required) and just the inser...

Sort a singly Linked list

The structure of the linked list is head.item = the number you want to sort head.next = the next item The only catch is that I need the singly linked list to sorted in constant space. ...

Top 10 Frequencies in a Hash Table with Linked Lists

The code below will print me the highest frequency it can find in my hash table (of which is a bunch of linked lists) 10 times. I need my code to print the top 10 frequencies in my hash table. I do not know how to do this (code examples would be great, plain english logic/pseudocode is just as great). I create a temporary hashing list ...

Array of linked lists in C++

Some code for context: class WordTable { public: WordTable(); ~WordTable(); List* GetListByAlphaKey(char key); void AddListByKey(char key); bool ListExists(char key); bool WordExists(string word); void AddWord(string word); void IncrementWordOccurances(string word); void Print(); private: List *_listArray[33]; int...

What is the time complexity of a size() call on a LinkedList in Java?

As the title asks, I wonder if the size() method in the LinkedList class takes amortized O(1) time or O(n) time. Thanks! ...

doubly linked list illustration

I'm trying to illustrate a doubly linked list problem. this is from an old test i've been studying lately. The question is as follows: draw what the final linked after this code: ListNode n1 = new ListNode(); ListNode n2 = new ListNode(); ListNode n3 = n1; n1.next = n2; n3.prev = n1; n1.next.prev = n3.next; Where I get lost is t...

Is there a way to copy a doubly LinkedList in Java without reference?

I am creating some doubly linked list of type Double and no matter how I declare another linked list of the same type, it always refers to the first list. Such as: LinkedList<LinkedList<Double>> trainingData = new LinkedList<LinkedList<Double>>(); LinkedList<LinkedList<Double>> newData = new LinkedList<LinkedList<Double>>(); Add some...

Finding the median of numbers in a LinkedList

How do you find the median of a list of numbers stored as a LinkedList in Java? I don't understand the Selection Algorithm that Wikipedia refers to. Bonus points if you can explain that. ...

Efficient data structure for fast random access, search, insertion and deletion

I'm looking for a data structure (or structures) that would allow me keep me an ordered list of integers, no duplicates, with indexes and values in the same range. I need four main operations to be efficient, in rough order of importance: taking the value from a given index finding the index of a given value inserting a value at a giv...

Qt: QList of QButtonGroup

Hey! I try to do the following QList<QButtonGroup*> groups; for (int i=0; i<nGroup; i++) { QButtonGroup *objects = new QButtonGroup(this); objects->setExclusive(false); for (int j=0; j<nObject; j++) { Led *tempLed = new Led(); tempLed->setAutoExclusive(false); ...

How can I delete a node from the middle of a C++ queue?

I have a linked list with a c-style ctor and dtor. I just got too frustrated when this if statement decided not to test true, putting me in an infinite loop. I dont understand why it will never test true. I am trying to delete a node (the address of a class object) from my LinkedList. Maybe someone could help me out? Node *Current = ...

Linkedlist Node in C+

I am learning a book on data structures, and complied their node in linked list example, and I receive this error: and Everything.cpp|7|error: expected unqualified-id before "int"| and Everything.cpp|7|error: expected `)' before "int"| ||=== Build finished: 2 errors, 0 warnings ===| The code for the node is: typedef struct Node { ...

C++ Deleting a node in Queue

Problem1: Deleting in a node in a list > 3 Description: Deletion of the sixth node in a list of seven, results in a print of only the first and last node. Available Node Pointers: next, prev, data Function to delete the specified node is in the LinkedList.cpp Name: DeleteNode. Function that traverses through the list to print the no...

How can I easily delete duplicates in a linked list in java?

How can I easily delete duplicates in a linked list in java? ...

Why does "delete node;" crash my C++ linked list application?

The jDeleteAfter method of my linked list class is supposed to delete the node immediately following the node passed as an argument. If it is doing that, I do not know, but it is abruptly closing my console application when "delete tlp;" (Temp List Pointer) gets read. My instructor, the users of a programming forum and I have yet to de...

Marshalling a Linked List

Apologies for duplicate posting. Hi I am having trouble marshalling a linked list from a DLL. ------C++ Structure and Function-------- struct localeInfo { WCHAR countryName[BUFFER_SIZE]; WCHAR localeName[BUFFER_SIZE]; localeInfo *next; } int GetSystemLocales(localeInfo **ppList); -----------C# Declarations----------- ...

When to Be Specific About the Type of List You Want

Let's say I have a class which, internally, stores a List of data: import java.util.List; public class Wrapper { private List<Integer> list; public Wrapper(List<Integer> list) { this.list = list; } public Integer get(int index) { return list.get(index); } } For the sake of this example, pretend it's a usefu...