doubly-linked-list

How do I change a singly-linked list to a doubly-linked list?

点点圈 提交于 2020-02-07 11:27:13
问题 I'm currently taking a Java class and the professor told us that a good practice to understand links would be to make a doubly linked list. I have made a singly linked list but I am having trouble converting it to a doubly linked list. So I was wondering if anybody could give me any suggestions on making sure my last number is connected to the previous one? And if the front number and last number connected to the null. Here is part of the code, if you wish for more of it just ask and I shall

How do I change a singly-linked list to a doubly-linked list?

强颜欢笑 提交于 2020-02-07 11:26:12
问题 I'm currently taking a Java class and the professor told us that a good practice to understand links would be to make a doubly linked list. I have made a singly linked list but I am having trouble converting it to a doubly linked list. So I was wondering if anybody could give me any suggestions on making sure my last number is connected to the previous one? And if the front number and last number connected to the null. Here is part of the code, if you wish for more of it just ask and I shall

Converting a sorted doubly linked list to a BST

末鹿安然 提交于 2020-01-14 05:59:06
问题 How can a sorted doubly linked list be converted to a balanced binary search tree. I was thinking of doing this the same way as converting an array to a balanced BST. Find the centre and then recursively convert the left part and the right part of the DLL. For example, 1 2 3 4 5 => 1 2 (3) 4 5 => 3 / \ 2 4 / \ 1 5 This is leads to the recurrence T(n) = 2T(n/2) + O(n). O(n) is for finding the centre. The time complexity is therefore O(nlogn). I was wondering if there is an algorithm that does

Circular Doubly Linked List - Segmentation fault: 11 [closed]

[亡魂溺海] 提交于 2020-01-07 03:57:14
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 3 years ago . I'm trying to implement a circular doubly linked list but I keep getting a segmentation fault: 11 error (I believe it's because of the add and delete functions). I have no idea whether my code is even close, but I can't get past this error to test it properly. This is the code I have that I believe is involved:

Java Iterator on doubly linked list

不羁岁月 提交于 2020-01-03 06:40:14
问题 Hi I'm very new to Java and have this problem with building a nested Iterator class for a Doubly Linked List. I'm getting this error on E next method when running the test program. The goal of the next method in the Iterator is to return the next item in the Doubly Linked List. Can anyone advice a fix on my code? Any help is greatly appreciated! Error message: Exception in thread "main" java.lang.NullPointerException at dlinkedlist.Deque$DoubleListIterator.next(Deque.java:51) public E next()

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

How is it possible to do binary search on a doubly-linked list in O(n) time?

与世无争的帅哥 提交于 2019-12-28 05:29:05
问题 I've heard that it's possible to implement binary search over a doubly-linked list in O(n) time. Accessing a random element of a doubly-linked list takes O(n) time, and binary search accesses O(log n) different elements, so shouldn't the runtime be O(n log n) instead? 回答1: It's technically correct to say that the runtime of binary search on a doubly-linked list is O(n log n), but that's not a tight upper bound. Using a slightly better implementation of binary search and a more clever analysis

c circular double linked-list: traverses fwd/rev for end node gives different pointer address

半城伤御伤魂 提交于 2019-12-25 06:35:18
问题 related post: c circular double linked-list delete_node - iterate traverses deleted node on first pass after delete All, implementing a search for node contianing line number 'x' prior to deleting that node, I ran across a problem where both forward and reverse searches identify the proper node, but the pointer for the caller's node address is reported differently by the reverse search than for the forward? This applies to the last node (hightest line number) only. If only the forwrd search

Get letter by letter to a doubly linked list

人走茶凉 提交于 2019-12-25 06:21:10
问题 I'm trying to write a program that takes a word letter by letter in every node of a doubly linked list and then with a function I wrote it will check if the word is a palindrome. When I compile my code I'm having problems in the part of the code it takes the input, so I would like to know how I can do it. int main(){ char c; Llista * list; Dada head = {0, NULL, NULL}; printf("insertar palabra para comprobar si es palindromo"); while((c=getchar()) != '\n'){ InsertAtTail(c); } palindromo(list);

Linked List implementation for a stack

早过忘川 提交于 2019-12-25 02:07:15
问题 Here is my implemetation of stack with linkedlist STACK using linked list STACK-EMPTY: if L.head == NIL return True else return False PUSH(x): x.next = L.head if L.head != NIL L.head.prev = x L.head = x x.prev = NIL POP(): x = L.head L.head = x.next x.next.prev = L.head return x would you validate this? how to improve ? thanks 回答1: You can improvement the consistency of your data structure: The prev of the list head is always NIL An element which is not in the list has next and prev set to