linked-list

Doubly Linked List Implementation with Pointers C++

被刻印的时光 ゝ 提交于 2019-12-30 11:28:12
问题 I am currently teaching myself C++ and am attempting to implement a doubly-linked list in C++ using pointers which is partially complete. I am aware that the code currently fails to deal with dangling nodes or output errors, both of which I will implement next. However, the code should atleast be able to construct a list object and add elements to it. Currently, I am getting an error when I attempt to call a constructor for the list, which says that I am requesting a conversion from

Is there a fast concat method for linked list in Java?

£可爱£侵袭症+ 提交于 2019-12-30 07:59:07
问题 How can I concat two linked lists in O(1) with Java via jdk1.6, google or apache commons collection or whatever? E.g. in the jdk there is only the addAll method which is O(n). Another feature I miss is to concat two lists where each of them could be in inverse order. To illustrate this assume two lists a->b->c and e->f->g could merged into a->b->c->e->f->g a->b->c->g->f->e c->b->a->e->f->g c->b->a->g->f->e Do you know of such a list implemenation or do I have to implement my own linked list?

List implementations: does LinkedList really perform so poorly vs. ArrayList and TreeList?

为君一笑 提交于 2019-12-30 05:45:11
问题 Taken from the Apache TreeList doc: The following relative performance statistics are indicative of this class: get add insert iterate remove TreeList 3 5 1 2 1 ArrayList 1 1 40 1 40 LinkedList 5800 1 350 2 325 It goes on to say: LinkedList is rarely a good choice of implementation. TreeList is almost always a good replacement for it, although it does use sligtly more memory. My questions are: What is with the ArrayList add , insert , and remove times crushing LinkedList ? Should we expect,

merging two sorted linked lists into one linked list in python

故事扮演 提交于 2019-12-30 05:18:10
问题 here is my code: def merge_lists(head1, head2): if head1 is None and head2 is None: return None if head1 is None: return head2 if head2 is None: return head1 if head1.value < head2.value: temp = head1 else: temp = head2 while head1 != None and head2 != None: if head1.value < head2.value: temp.next = head1 head1 = head1.next else: temp.next = head2 head2 = head2.next if head1 is None: temp.next = head2 else: temp.next = head1 return temp pass the problem here is stucked in the infinite loop

C# equivalent for java arraylist supporting get, set and remove certain Index

一世执手 提交于 2019-12-30 04:01:05
问题 I am a Java programmer, I have used a Java ArrayList before and now I want to have something like that in C#. Some of options I need are in this Java code: String[] strs = new String[]{"str1" , "str2" , "str3" , "str4"}; ArrayList arrayList = new ArrayList(35); arrayList.add(strs[0]); arrayList.add(strs[1]); arrayList.remove(0); arrayList.set(0, strs[2]); String s = (String) arrayList.get(1); I used C# ArrayList and LinkedList , but they don't have these simple options that I need. Is there

Can an XOR linked list be implemented in C++ without causing undefined behavior?

纵然是瞬间 提交于 2019-12-30 03:56:07
问题 An XOR linked list is a modified version of a normal doubly-linked list in which each node stores just one "pointer" instead of two. That "pointer" is composed of the XOR of the next and previous pointers. To traverse the list, two pointers are needed - one to the current node and one to the next or previous node. To traverse forward, the previous node's address is XORed with the "pointer" stored in the current node, revealing the true "next" pointer. The C++ standard causes a bunch of

java linkedlist slower than arraylist when adding elements?

一曲冷凌霜 提交于 2019-12-30 02:24:14
问题 i thought linkedlists were supposed to be faster than an arraylist when adding elements? i just did a test of how long it takes to add, sort, and search for elements (arraylist vs linkedlist vs hashset). i was just using the java.util classes for arraylist and linkedlist...using both of the add(object) methods available to each class. arraylist out performed linkedlist in filling the list...and in a linear search of the list. is this right? did i do something wrong in the implementation maybe

Hashmap and how this works behind the scene [duplicate]

混江龙づ霸主 提交于 2019-12-29 08:32:25
问题 This question already has answers here : How does Java HashMap store entries internally (3 answers) Closed 6 years ago . quick question to be sure I understood well how HashMap in java works. Here is an example of code: //String key = new String("key"); //String val = new String("value"); String key = "key"; String val = "value"; HashMap map = new HashMap(); map.put(key, val); System.out.println("hashmap object created. Its key hashcode = "+key.hashCode()); // the hashcode is 106079 System

When to use GlueList over ArrayList or LinkedList? [duplicate]

元气小坏坏 提交于 2019-12-29 07:17:49
问题 This question already has answers here : When to use LinkedList over ArrayList in Java? (32 answers) Closed 4 years ago . I came across new list implementation which called GlueList I want to know when i should use over ArrayList or LinkedList. 回答1: To be honest, if you cant decide after reading info at GlueList which states in few sentences why it is better (different) and even have benchmark to see the real values and also Big-O notation - you are not in position where you have to think

how to remove a object from linked list in java?

醉酒当歌 提交于 2019-12-29 05:34:11
问题 i have one problem with my code ,i did a sample program to display the emp details from a linked list,now the problem when i trying to delete a particular entry means it doesn't work,i hope i did some mistake in my code could you suggest how to do that? import java.util.*; class EmpDedup { int record; String fprint; int fid; EmpDedup(int record, String fprint, int fid) { this.record = record; this.fprint = fprint; this.fid = fid; } public int getRecord() { return record; } public String