Exchange two nodes in LinkedList
By : Yossef Elnaggar
Date : March 29 2020, 07:55 AM
around this issue I don't know the implementation, but if your nodes have simply one value (in addition to the next and previous links), you can just swap the values.
|
how to add nodes to kernel linkedlist
By : Kaz
Date : March 29 2020, 07:55 AM
help you fix your problem @Sweet, I had developed a small kernel module using kernel exposed list as below, Please go through and get back to me if you have any doubts or feedback. code :
void todo_add_entry(struct todo_struct *new)
{
#ifdef QUEUE
list_add_tail(&new->list, &first.list);
#else
list_add(&new->list, &first.list);
#endif
}
void todo_del_entry(struct todo_struct *new)
{
struct todo_struct *str, *temp;
list_for_each_entry_safe(str, temp, &first.list, list)
{
if((str->priority == new->priority) && (str->name == new->name))
{
list_del(&str->list);
#ifdef DEBUG
dmsg("Same:%d \t %d\n", str->priority, new->priority);
#endif
kfree(str);
}
}
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)
static long
list_minor_ioctl(struct file *filp, U32 cmd, unsigned long arg)
#else
static int
list_minor_ioctl(struct inode *inode, struct file *filp, U32 cmd,
unsigned long arg)
#endif
{
S32 res = 0;
S32 err = 0;
struct todo_struct *new;
struct test *a;
if(_IOC_TYPE(cmd) != IOCTL_LIST_MAGIC)
return -ENOTTY;
if(_IOC_NR(cmd) > IOCTL_MAX_CMDS)
return -ENOTTY;
if(_IOC_DIR(cmd) & _IOC_READ)
err = !access_ok(VERIFY_WRITE, (void __user*) arg, _IOC_SIZE(cmd));
if(_IOC_DIR(cmd) & _IOC_WRITE)
err = !access_ok(VERIFY_READ, (void __user*) arg, _IOC_SIZE(cmd));
if(err)
return -EFAULT;
new = kmalloc(sizeof(*new), GFP_KERNEL);
a = (struct test *) arg;
switch(cmd)
{
case IOCTL_LIST_ADD:
new->priority = a->priority;
new->name = a->name;
INIT_LIST_HEAD(&new->list);
todo_add_entry(new);
break;
case IOCTL_LIST_DEL:
new->priority = a->priority;
new->name = a->name;
#ifdef DEBUG
dmsg("prio:%d \t name:%s \n", new->priority, new->name);
#endif
todo_del_entry(new);
break;
default: /* Default case --> Ignore, will never get executed */
break;
}
return res;
}
|
Tasks with LinkedList nodes
By : Вован Вованович
Date : March 29 2020, 07:55 AM
it fixes the issue Due to variable closure, you should declare the variable that is captured in your lambda expression within the body of your loop. Otherwise, the task's reads of the first variable would suffer a race condition with the main thread's subsequent updates to it. code :
first = linkedList.First;
while (iterator != null)
{
// ...
var current = first;
Task.Factory.StartNew(() => run(current));
// ...
}
|
Deleting all nodes and setting root to null in a binary search tree?
By : Basma
Date : March 29 2020, 07:55 AM
I hope this helps . The tutorial you are following are about the language C which differs greatly from Java. In C you have to allocate and free memory manually (by the malloc and free methods in the link you listed). However, Java manages all that behind the scenes. You could say that Java's version of malloc is new. But for freeing the memory Java has a garbage collector that free up memory by deleting unreferenced objects. To 'delete' your tree in Java all you have to do is de-reference your root like so: code :
public void deleteTree() {
root = null;
}
|
LinkedList to store LinkedList of Nodes
By : bUng
Date : March 29 2020, 07:55 AM
help you fix your problem Okay, I just gave it a shot - using the Java Collection Framework as mentioned by Kami and Roman C. To avoid confusion I always used the full qualified name of the interfaces/classes involved - even though that makes the code look big and ugly. I used the java.util.LinkedList which implements the java.util.List as well as the java.util.Deque interface. The latter one gives you the methods to treat it as a stack.
|