linked-list

How can I get the children process list in kernel code

与世无争的帅哥 提交于 2019-12-21 17:23:20
问题 I want to get to the children task (process) list of a process, here is the code: void myFunc() { struct task_struct* current_task; struct task_struct* child_task; struct list_head children_list; current_task = current; children_list = current_task->children; child_task = list_entry(&children_list,struct task_struct,tasks); printk("KERN_INFO I am parent: %d, my child is: %d \n", current_task->pid,child_task->pid); } The current pid is right, but the child pid is not correct. What am I doing

Count number of nodes in a linked list that may be circular

我的梦境 提交于 2019-12-21 16:18:35
问题 Here is the problem, it is from Sedgwick's excellent Algorithms in Java (q 3.54) Given a link to a node in a singly linked list that contains no null links (i.e. each node either links to itself or another node in the list) determine the number of different nodes without modifying any of the nodes and using no more than constant memory space. How do you do it? scan through the list once using the hare and tortoise algorithm to work out whether it is circular in any way, and then scan through

C++ Segmentation when using erase on std::list

有些话、适合烂在心里 提交于 2019-12-21 12:13:04
问题 I'm trying to remove items from a C++ linked list using erase and a list iterator: #include <iostream> #include <string> #include <list> class Item { public: Item() {} ~Item() {} }; typedef std::list<Item> list_item_t; int main(int argc, const char *argv[]) { // create a list and add items list_item_t newlist; for ( int i = 0 ; i < 10 ; ++i ) { Item temp; newlist.push_back(temp); std::cout << "added item #" << i << std::endl; } // delete some items int count = 0; list_item_t::iterator it; for

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

What is the Definition of a Lisp Cons Cell?

懵懂的女人 提交于 2019-12-21 07:34:46
问题 What exactly is the definition of a Common Lisp Cons Cell? How is a Cons Cell different than a standard linked list item? After all, both the cons cell and the linked list item have a value and a pointer to the next cell or item... or is this understanding wrong? 回答1: Cons cells in general hold two pointers that can point to anything. General usage of course is to point to a "value" with the left one, and to another Cons cell (or nil) with the "right" one. 回答2: A cons cell is closer to a

Maximum Size List in Java

故事扮演 提交于 2019-12-21 07:13:49
问题 It's useful to me to have a data structure in Java that has all the functionality of a List, but has a maximum storage capacity, and drops older data when newer data is added. Conceivably at some point I might want to implement a fixed size Queue which keeps a more general ordering of the data, and drops the old data lowest in that ordering, but that's the for the future. At the moment I'm implementing it like this: public class FixedSizeList<T> { private final int maxSize; private final

Invert linear linked list

穿精又带淫゛_ 提交于 2019-12-21 06:28:30
问题 a linear linked list is a set of nodes. This is how a node is defined (to keep it easy we do not distinguish between node an list): class Node{ Object data; Node link; public Node(Object pData, Node pLink){ this.data = pData; this.link = pLink; } public String toString(){ if(this.link != null){ return this.data.toString() + this.link.toString(); }else{ return this.data.toString() ; } } public void inc(){ this.data = new Integer((Integer)this.data + 1); } public void lappend(Node list){ Node

compare list with multiple attributes involving a boolean

浪尽此生 提交于 2019-12-21 05:45:08
问题 I have some classes that implement the comparator interface to sort an ArrayList by adding patient objects, I want to sort the list by multiple attributes and have no problem sorting with just Enums, however I want to override this sort by sorting with a boolean. I know I cannot use the compareTo method as it is not a Wrapper class but I am not able to find a suitable way to sort the list via boolean . Any help would be greatly appreciated. public Patient(int nhsNumber, String name, Status

Don't updating JTable

て烟熏妆下的殇ゞ 提交于 2019-12-21 05:36:16
问题 I found sample with updating data, but it uses DefaultTableModel. When I created my own TableModel and my own data class, when I add data into JTable it doesn't update. How do I add a listener to my TableModel? Here is my code: package by; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.util.LinkedList; import javax.swing.AbstractAction; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing