windows内核驱动中的链表结构
2021-04-14 05:29
标签:node src || 结构体 cout windows plist driver bool windows内核驱动中的链表结构与数据结构中的链表结构在构造上有很大不同,以循环双链表为例 数据结构中的链表结构: 数据就像集装箱,可以直接放置在火车上,而节点就像每节之间的挂接装置. 内核驱动中的链表结构: 数据就像车厢,自带挂接装置(节点) 1.链表结构体不同 数据结构中的链表结构,包含有节点和数据, struct DataList{ DataType data; struct DataList* next; struct DataList* prev; }; 驱动中的链表结构,仅包含有节点,没有数据。 struct DriverList{ struct DriverList* next; struct DriverList* prev; }; 2.数据结构中的数据,可以直接封装在链表结构体中; 而在驱动链表结构中,要将链表结构封装在数据中, struct DataEntry{ struct DriverList node; DataType data; }; 以下是示例代码 output: stu->name = student0, stu->age = 0, stu->weight = 0 windows内核驱动中的链表结构 标签:node src || 结构体 cout windows plist driver bool 原文地址:https://www.cnblogs.com/endenvor/p/8967659.html 1 #pragma once
2
3 typedef struct List {
4 struct List * next;
5 struct List * prev;
6 }List, *Plist;
7
8 void initList(Plist head);
9 bool isEmpty(Plist pHead);
10 void addFirst(Plist pHead, Plist pNewNode);
11 void addLast(Plist pHead, Plist pNewNode);
12 void traverse(Plist pHead, void (*pfun)(void *));
13
14 void initList(Plist head)
15 {
16 head->next = head;
17 head->prev = head;
18 }
19
20
21 bool isEmpty(Plist pHead)
22 {
23 if (pHead->next == pHead || pHead->prev == pHead)
24 return true;
25 return false;
26 }
27
28 void addFirst(Plist pHead, Plist pNewNode)
29 {
30 // list is not empty
31 if (pHead->next != pHead)
32 {
33 pHead->next->prev = pNewNode;
34 pNewNode->next = pHead->next;
35 }
36 else
37 {
38 pHead->prev = pNewNode;
39 pNewNode->next = pHead;
40 }
41 pHead->next = pNewNode;
42 pNewNode->prev = pHead;
43 }
44
45 void addLast(Plist pHead, Plist pNewNode)
46 {
47 // list is not empty
48 if (pHead->next != pHead)
49 {
50 pNewNode->prev = pHead->prev;
51 pHead->prev->next = pNewNode;
52 }
53 else
54 {
55 pHead->next = pNewNode;
56 pNewNode->prev = pHead;
57 }
58 pHead->prev = pNewNode;
59 pNewNode->next = pHead;
60 }
1 #include "stdafx.h"
2 #include
stu->name = student1, stu->age = 1, stu->weight = 1.2
stu->name = student2, stu->age = 2, stu->weight = 2.4
stu->name = student3, stu->age = 3, stu->weight = 3.6
stu->name = student4, stu->age = 4, stu->weight = 4.8
stu->name = student5, stu->age = 5, stu->weight = 6
stu->name = student6, stu->age = 6, stu->weight = 7.2
stu->name = student7, stu->age = 7, stu->weight = 8.4
stu->name = student8, stu->age = 8, stu->weight = 9.6
stu->name = student9, stu->age = 9, stu->weight = 10.8
请按任意键继续. . .