linked-list

How does LinkedList work internally in Java?

假装没事ソ 提交于 2019-12-04 19:29:03
问题 As far as I know, the concept of a linked list is a bunch of object connected to each other by having a 'next' and sometimes 'previous' attribute to traverse the objects. I noticed in Java, you can create a LinkedList object...but treat it like an array/list/sequence by using the same methods such as .add(), .get(), etc. So, is LinkedList internally an array-like sequence? 回答1: So, is LinkedList internally an array-like sequence? No. It's a series of instances of a private nested class Entry

Declaring static generic variables in a generic class

纵然是瞬间 提交于 2019-12-04 18:01:24
问题 I've read that you cannot declare static variables/methods inside a generic class and I really have no idea how to solve my problem or work around it so I ask for your guidance. What I want is a generic "index" that all of my core classes will extend. I'm creating a game-engine and an example is that I will have different gamestates who all extends State who in turn extends Nexus<State> . The reason I want the static head and tail is so that I can keep a linked list of all gamestates since

Bubble Sort Manually a Linked List in Java

梦想与她 提交于 2019-12-04 17:23:54
This is my first question here. I am trying to manually sort a linked list of integers in java and I can not figure out what is wrong with my code. Any suggestions? I don't get any error, however I still have my output unordered. I tried a few different ways, but nothing worked. I appreciate if anyone can help me with that. public class Node { int data; Node nextNode; public Node(int data) { this.data = data; this.nextNode = null; } public int getData() { return this.data; } } // Node class public class DataLinkedList implements DataInterface { private Node head; private int size; public

Linked List, insert at the end C++

女生的网名这么多〃 提交于 2019-12-04 16:50:21
I was writing a simple function to insert at the end of a linked list on C++, but finally it only shows the first data. I can't figure what's wrong. This is the function: void InsertAtEnd (node* &firstNode, string name){ node* temp=firstNode; while(temp!=NULL) temp=temp->next; temp = new node; temp->data=name; temp->next=NULL; if(firstNode==NULL) firstNode=temp; } What you wrote is: if firstNode is null, it's replaced with the single node temp which has no next node (and nobody's next is temp ) Else, if firstNode is not null, nothing happens, except that the temp node is allocated and leaked.

Runner technique to combine two equal Linked Lists

给你一囗甜甜゛ 提交于 2019-12-04 16:26:38
问题 So, I am facing a doubt here. I was reading the book Cracking the coding Interview. The following text is written over there. Suppose you had a linked list a1->a2....->an->b1->b2....bn , and you want to rearrange it into a1->b1->a2->b2->.....an->bn . You don't know the length of the linked list but all you know is that it is an even number. (Here both the linked lists are of same length) You could have one pointer p1 (fast pointer) move every two elements for every one move that p2 makes.

Swapping nodes in double linked list

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 16:10:26
I'm trying to implement a function that swap two nodes of my double linked list, in order to sort the content of the current directory. But my function seems to 'delete' some elements of my list, here is the code : void node_swap(struct s_node *left, struct s_node *right) { struct s_node *tmp; tmp = left->prev; if (tmp) { tmp->next = right; right->prev = tmp; } else right->prev = NULL; left->prev = right; left->next = right->next; right->next = left; right->next->prev = left->prev; } I can't see what's wrong in this ? Say this is your initial structure TMP -> L -> R -> X You are not updating

Create Linked List in AS3

允我心安 提交于 2019-12-04 16:00:52
how can I create a linked list in actionScript 3.0? I have a project that I should get some integer numbers from the user and sort them by a tree algorithm for example heap-sort and show the tree in flash, I think I should use linked list to sort the data by tree algorithms. so anybody know how can I create a linked list which I can insert nodes, delete nodes and pass over the nodes, just like C++ linked list. Thanks. SA You can use or take as an exmaple as3Commons linked list implementation . They provide very beautiful implementation with very good abstraction layer. If you have access to

C Linked-list Destroy Function

爱⌒轻易说出口 提交于 2019-12-04 14:32:01
I'm trying to learn C, and as many people, I've been a little stuck with pointers. Anyways, I made a recursive function that destroys my linkedlist, but as I've debugged, when I'm back from the function the head of the list is not null as it should be, so I'm guessing it's some basic misunderstanding with pointers. Here's the function: void destroy(struct node* n){ if(!n) return; destroy(n->next); free(n); n = NULL; } Thanks in advance. spt025 void deleteList(struct node** head_ref) { struct node* current = *head_ref; struct node* next; while (current != NULL) { next = current->next; free

C generic linked-list

你离开我真会死。 提交于 2019-12-04 13:51:28
问题 I have a generic linked-list that holds data of type void* I am trying to populate my list with type struct employee, eventually I would like to destruct the object struct employee as well. Consider this generic linked-list header file (i have tested it with type char*): struct accListNode //the nodes of a linked-list for any data type { void *data; //generic pointer to any data type struct accListNode *next; //the next node in the list }; struct accList //a linked-list consisting of

Flatten binary search to in order singly linked list [C]

醉酒当歌 提交于 2019-12-04 13:34:48
问题 I am trying to flatten a binary search tree to a singly linked list. Binary search tree: 6 / \ 4 8 / \ \ 1 5 11 / 10 Flattened Singly Linked List: 1 -> 4 -> 5 -> 6 -> 8 -> 10 -> 11 I can't seem to figure this out for some reason. I have a struct for the tree nodes: typedef stuct node { int key; struct node *left; struct node *right; } Node; I have a function to create and allocate memory to the tree node: Node* newNode (int key) { Node *new = malloc (sizeof(Node)); new->left = NULL; new-