doubly-linked-list

How to do a cyclic doubly link list add method in java

故事扮演 提交于 2019-12-13 03:52:36
问题 I am implementing the add(E) method in the cyclic DoublyLinkedList class as well as the Node inner class. Node should be implemented as a private inner class. DoublyLinkedList's "first" attribute should point to the first node in the list. Its "size" attribute should store the number of elements in the list. I am struggling on my add method, because it feels like nothing is wrong and I don't know what else I can add this this code that can fix it. Therefore a brief introduction on what the

How do I convert iterator to const_iterator in my custom list iterator class?

…衆ロ難τιáo~ 提交于 2019-12-13 03:18:16
问题 I am trying to implement my own doubly-linked list (my_list) code in C++, and in particular an iterator class for my list. My problem is I want to have an implicit conversion from iterator to const_iterator so that for example the code my_list::iterator it = l.begin(); where l is an instance of my_list compiles. However, I cannot find a way to do this without my compiler complaining. Here is the code implementing the list nodes and the iterator class: template<class T> class node { node(const

The real time efficiency of LinkedList in Java

∥☆過路亽.° 提交于 2019-12-12 18:21:58
问题 We know the Double LinkedList Data Structure has an advantage of inserting a node in O(1) time if you already got the node before or after the location you want to insert. (e.g. if you have a double linked list: A-B-C-D, if you already got the node C, then it only takes O(1) time to insert a new Node before or after the node C). If you manually construct a double linked list in Java/C++, it is fairly easy to understand, but I recently am interested in the LinkedList library in Java which is a

Recursively insert at the end of doubly linked list

橙三吉。 提交于 2019-12-12 06:15:26
问题 I have a doubly linked list, and I want to insert an element at the end of the list recursively. I have a method now that does this without recursion, and it works. I just can't seem to understand how to do it with recursion. Inserting at the end of a singly linked list with recursion is quite easy to understand I think, so I hope that someone can explain how to it do it when the list is doubly linked. Here is my normal insertion method that I want to make recursive: public void insert(T

std::list implementation & pointer arithemetic.

纵饮孤独 提交于 2019-12-12 04:56:30
问题 As I understand it, std::vector allocates/de-allocates all the memory it requires each time it's elements grows or shrinks, therefore pointer arithmetic can be used to iterate the vector elements. std::list on the other hand uses a double linked list, with each element pointing to the next and previous element. Assuming(possibly wrongly) that std::list allocates it's memory dynamically, so memory is allocated, if and when required, incrementally. How is std::list still able to offer pointer

Remove a node in LinkedList in Java given the node reference

六眼飞鱼酱① 提交于 2019-12-12 01:11:58
问题 For example, if I have LinkedList LinkedList<Integer> ll = new LinkedList<Integer>(); ll.add(1); ll.add(2); ll.add(3); Integer x = new Integer(10); ll.add(x); ll.add(4); // now the list looks like 1->2->3->10->4 // what if I want to remove 10 and I still have the reference to that node x // what is the API of that // somethings like ll.remove(x)... If I implement a doubly linked list by myself, just currentNode.prev.next = currentNode.next; currentNode.next.prev = currentNode.prev; Does Java

Double linked list and void pointers [find method]

筅森魡賤 提交于 2019-12-12 01:06:34
问题 i wrote this double linked list with void pointers typedef struct list_el { void *data; struct list_el *prev; struct list_el *next; } list_el; typedef struct linked_list { int n_el; /*number of elements*/ list_el * head; /*pointer to the head*/ list_el * tail; /*pointer to the head*/ } linked_list; and i wrote those functions to handle with it. /*for list_el allocation*/ list_el * new_el ( void ) { return (list_el *) malloc(sizeof(list_el)); } /*list initialization*/ void init_list(linked

How to remove duplicates from a doubly linked list by full name

孤街醉人 提交于 2019-12-11 20:33:25
问题 I have a doubly linked list in which it stores player objects. The player object contains first name, last name, level and experience. Im trying to create a function that will remove a duplicate player object. For instance, if I enter Luis suarez and then he is entered again, I want the function to ask the user to enter the duplicates name and delete one of the luis suarez players (preferably the one last in the list). I've tried many things and none of them work nor delete anything. Can

How to turn my doubly linked list container into a “square list” container

荒凉一梦 提交于 2019-12-11 20:14:11
问题 Hi I have made a doubly linked list container. For a project I now have to turn the doubly linked list into a square list. What I mean by square list is that the data will be stored in a square. So for example 4 elements would be stored like this: 10 30 20 40 5 elements would be stored like this: 10 30 50 20 40 10 elements would be stored like this: 10 40 70 100 20 50 80 30 60 90 Basically the number of rows or columns cannot exceed the square root of the ceiling of the size of the list. What

c circular double linked-list: rev traverse gives different list-pointer address for same node

落花浮王杯 提交于 2019-12-11 19:53:51
问题 related post 1: c circular double linked-list delete_node - iterate traverses deleted node on first pass after delete related post 2: c circular double linked-list: traverses fwd/rev for end node gives different pointer address In working with a circular double linked-list, I have, with help from stackoverflow, created a delete_node function that uses both forward or reverse iterations on the list to arrive at the node to be deleted. The function takes the address of the linked-list as the