-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.h
More file actions
70 lines (46 loc) · 1.61 KB
/
list.h
File metadata and controls
70 lines (46 loc) · 1.61 KB
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
/*
* In order to maintain the implicit numbering,
* use a linked list structure here !!
* Each node are listed in increasing order of occ.
* And for the same occ, leaf nodes always precede the internal nodes.
* Structure: dummy head + double linked
*/
#ifndef _LIST_H_
#define _LIST_H_
#include <stdio.h>
#include <stdlib.h>
#include "tree.h"
// define the node structure
// double link
struct _ListNode{
TreeNode trn;
struct _ListNode *prev;
struct _ListNode *next;
};
// define the pointer
typedef struct _ListNode *ListNode;
typedef struct _ListNode *List;
// ListNode
ListNode ListNodeCreate(TreeNode); // just include the treenode, with a null next pointer
ListNode ListNodeDestroy(ListNode); // recursion, delete this node and all next nodes
// connection
ListNode GetPrev(ListNode);
ListNode GetNext(ListNode);
void ConnectAsPrev(ListNode cur, ListNode prev);
void ConnectAsNext(ListNode cur, ListNode next);
// List
List ListCreate(void);
List ListDestroy(List);
void ListInsert(List, ListNode); // insert listnode into list, similar to insertion sort
void ListShow(List);
// the following two search for related tree node and list node
TreeNode GetTreeNode(ListNode);
ListNode GetListNode(List, TreeNode);
// for a given listnode, use its treenode to find its parent treenode,
// and return the listnode that encapsulate its parent treenode
ListNode FindParentListNode(ListNode LN);
// get the first element of the list, usually the listnode that packs the NYT treenode
ListNode GetListHead(List);
// reassign the list first element
void AssignListHead(List, ListNode);
#endif