doubly-linked-list

Print a doubly linked list in reverse order?

风格不统一 提交于 2019-12-24 10:49:50
问题 My minimal reproducible example: #include <stdio.h> #include <stdlib.h> typedef struct NodeStruct Node; //struct for each office item struct NodeStruct { int id; struct NodeStruct *next; struct NodeStruct *prev; //Create doubly linked list node }; /** Structure for the whole list, including head and tail pointers. */ typedef struct { /** Pointer to the first node on the list (or NULL ). */ Node *head; Node *last; } List; List *list; List *makeList(); static void *addRecord(List *list, int

Find the minimum element in a doubly linked list not working

ぐ巨炮叔叔 提交于 2019-12-24 09:38:54
问题 I have written up this code, to find the minimum of a set of numbers within a linked list. public DLNode<T> getMinimum() { if (isEmpty()) { return null; } DLNode<T> curr = head; DLNode<T> min = curr; T temporaryMinimum = head.getElement(); while (curr.getElement() != null) { if ((Integer) temporaryMinimum < (Integer) curr.getElement()) { min = curr; } curr = curr.getNext(); } return min; } I am testing it using this code block public static void getMinElement(){ int[] data = {2, 3, 5, 1, 6};

Creating Doubly Linked List from text file on C

吃可爱长大的小学妹 提交于 2019-12-24 09:04:03
问题 I have to make a doubly linked list out of a text file in which every row has a time and temperature. Fore example each row is like this: 12:48 23.69 So I'm having trouble putting the data into a doubly linked list. I don't know how to implement it. So I did an array of the typedef struct of the elements and was hoping I could start with the first element of the array and point the next to the second element of the array. Here's what I have... So here's my header file for the doubly linked

Bubble-sorting doubly linked list

你。 提交于 2019-12-24 03:30:33
问题 I have a problem with my bubble-sorting function for the doubly linked list. It is working when I'm sorting the nodes in the singly linked way (only with ->next), but I can't make it work with ->prev pointers. Here is the code I'm using: void sort(int count) { struct data *tmp,*current,*nextone; int i,j; for(i=0;i<count;i++) { current = first; for(j=0;j<count-1-i;j++ ) { if(current->number > current->next->number) { nextone = current->next; current->next = nextone->next; nextone->next =

Doubly Linked List to JSON

我们两清 提交于 2019-12-23 11:59:44
问题 I've a three dimensional structure ... actually a doubly linked list with six nodes i.e. left, right, up, down, in, out. if one node is on the right side of other then that node will be defiantly on the left side of the first one. like Actually this is a 3D structure, but for understanding purposes, I've given a 2D example. Now I've to convert it in JSON format, to send this data through WCF to a client, but as it contains loops so it couldn't be converted to JSON. I've these questions Can

Doubly Linked List to JSON

孤街浪徒 提交于 2019-12-23 11:59:00
问题 I've a three dimensional structure ... actually a doubly linked list with six nodes i.e. left, right, up, down, in, out. if one node is on the right side of other then that node will be defiantly on the left side of the first one. like Actually this is a 3D structure, but for understanding purposes, I've given a 2D example. Now I've to convert it in JSON format, to send this data through WCF to a client, but as it contains loops so it couldn't be converted to JSON. I've these questions Can

difference between double-ended linked lists and doubly-linked list

我只是一个虾纸丫 提交于 2019-12-21 08:17:06
问题 I don't understand difference between a double-ended and doubly-linked list. What is the major difference between the two? 回答1: In a doubly linked list, each node has two pointers. One towards its next node and another one towards its previous node. In a double-ended linked list, each node has just one pointer which points to its next node. Its difference from the single-ended linked list is that instead of just one "head" node, it contains two pointers of this kind ("first" and "last"), so

difference between double-ended linked lists and doubly-linked list

≯℡__Kan透↙ 提交于 2019-12-21 08:16:25
问题 I don't understand difference between a double-ended and doubly-linked list. What is the major difference between the two? 回答1: In a doubly linked list, each node has two pointers. One towards its next node and another one towards its previous node. In a double-ended linked list, each node has just one pointer which points to its next node. Its difference from the single-ended linked list is that instead of just one "head" node, it contains two pointers of this kind ("first" and "last"), so

converting a binary search tree to doubly linked list

ⅰ亾dé卋堺 提交于 2019-12-20 10:55:56
问题 This question was asked in a recent coding interview. Q : Given a binary tree, write a program to convert it to a doubly linked list. The nodes in the doubly linked list are arranged in a sequence formed by a zig-zag level order traversal My approach i could always do the zig-zag level order traversal of the tree and store it in an array an then make a double linked list. but the question demands for a in-place solution. can anyone help in explaining the recursive approach should be used? 回答1

c circular double linked-list delete_node - iterate traverses deleted node on first pass after delete

巧了我就是萌 提交于 2019-12-20 03:54:08
问题 All, in GNU c, I have a circular doubly linked-list I am trying to implement a delete_node function on. It works fine for all nodes except node 0. It does delete (free()) node 0, but the first time the list is traversed after deleting node 0, it is still present for the first pass causing the conditional to stopping the iteration to fail. The basics of the implementation are: struct record { char *line; int lineno; int linetype; struct record *prev; struct record *next; }; typedef struct