blob: 06f97f295c0fc2f5a3792ab3f53c01d6a53244db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// "C Primer Plus" Chapter17 practice 17 practice problem 2
/*list.h--简单列表类型的头文件*/
#ifndef LIST_H_
#define LIST_H_
#include <stdbool.h>
#include <stdint.h> //uint32_t
/*特定与程序的声明*/
#define VOLTLEN 96
#define TEMPLEN 96
typedef struct can
{
uint32_t t;
double volt[VOLTLEN];
uint8_t temp[TEMPLEN];
};
/*一般类型定义*/
typedef struct can Item;
typedef struct node
{
Item item;
struct node * next;
}Node;
typedef struct list
{
Node * head;
Node * end;
}List;
/*函数原型*/
/*操作: 初始化一个列表 */ //operation
/*操作前: plist指向一个列表 */ //preconditions
/*操作后: 该列表被初始化为空列表 */ //postconditions
void InitializeList(List * plist);
/*操作: 确定列表是否为空列表 */
/*操作前: plist指向一个已经初始化的列表 */
/*操作后: 如果该列表为空则返回true; 否则返回false*/
bool ListIsEmpty(const List * plist);
/*操作: 确定列表是否已满*/
/*操作前: plist指向一个已初始化的列表*/
/*操作后: 如果该列表为空则返回true; 否则返回false*/
bool ListIsFull(const List * plist);
/*操作: 确定列表中项目的个数*/
/*操作前: plist指向一个已初始化的列表*/
/*操作后: 返回该列表中项目的个数*/
unsigned int ListItemCount(const List * plist);
/*操作: 在列表尾部添加一个项目*/
/*操作前: item是要被增加到列表的项目*/
/* plist指向一个已初始化的列表*/
/*操作后: 如果可能的话,在列表尾部添加一个新项目,*/
/* 函数返回true;否则函数返回false*/
bool AddItem(Item item, List * plist);
/*操作: 把一个函数作用于列表中的每个项目*/
/*操作前: plist指向一个已出书画的列表*/
/* pfun指向一个函数,该函数接受*/
/* 一个Item参数并且无返回值*/
/*操作后: pfun指向的函数被作用到*/
/* 列表中的每个项目一次*/
void Traverse(const List * plist, void (* pfun)(Item item));
/*操作: 释放已分配的内存(如果有)*/
/*操作前: plist指向一个已初始化的列表*/
/*操作后: 为该列表分配的内存已被释放*/
/* 并且该列表被置为空列表*/
void EmptyTheList(List * plist);
#endif // LIST_H_
|