-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAberranceTree.cpp
More file actions
947 lines (869 loc) · 25.2 KB
/
Copy pathAberranceTree.cpp
File metadata and controls
947 lines (869 loc) · 25.2 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
/*******************************************************************************
*
* Copyright (c) all 2009 黄奇 All rights reserved
* FileName : AberranceTree.h
* D a t e : 2010.3.21
* 功 能 : 红黑树定义文件
* 说 明 :
*
*
*******************************************************************************/
#include "AberranceTree.h"
#include "Tools.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
/*******************************************************************************
*
* 函 数 名 : AberranceTree
* 功能描述 : AberranceTree构造函数
* 参数列表 : 无
* 说 明 :
* 返回结果 : 无
*
*******************************************************************************/
AberranceTree::AberranceTree():m_pSentinel(NULL), m_pRoot(NULL),m_pHead(NULL),
m_pLast(NULL)
{
m_pSentinel = new AberrTreeNode ;
if (m_pSentinel == NULL)
{
exit(EXIT_FAILURE) ;
}
m_pSentinel->color = b_black ;
m_pSentinel->left = m_pSentinel ;
m_pSentinel->right = m_pSentinel ;
m_pSentinel->parent = m_pSentinel ;
m_pRoot = m_pSentinel ;
}
/*******************************************************************************
*
* 函 数 名 : ~AberranceTree
* 功能描述 : AberranceTree析构函数
* 参数列表 : 无
* 说 明 :
* 返回结果 : 无
*
*******************************************************************************/
AberranceTree::~AberranceTree()
{
if (m_pRoot != m_pSentinel)
{
Destory(m_pRoot) ;
m_pRoot = NULL ;
}
if (m_pSentinel != NULL)
{
delete m_pSentinel ;
m_pSentinel = NULL ;
}
m_pHead = NULL ;
m_pLast = NULL ;
}
/*******************************************************************************
*
* 函 数 名 : Insert
* 功能描述 : 向红黑树插入一个节点
* 参数列表 : _nAddr -- 要指令的地址值
* 说 明 :
* 返回结果 : 如果成功,返回指向节点的指针
*
*******************************************************************************/
AberrTreeNode* AberranceTree::Insert(IN unsigned int _nAddr, IN char *pDump, int nLen)
{
AberrTreeNode * pNode = m_pRoot ;
AberrTreeNode * tmp = NULL ;
// 这里还要判断pDump是不是为空
if (NULL == pDump)
{
OutputDebugString("Dump为空!\r\n") ;
return 0 ;
}
if (nLen <= 0 || nLen >= DUMPSIZE)
{
OutputDebugString("DumpSize不对!\r\n") ;
return 0 ;
}
// 先判断树中有没有相同的结点,因为一条指令可能会跑很多次
if (NULL != m_pRoot)
{
tmp = FindEx(_nAddr, pDump, nLen) ;
if (NULL != tmp)
{
++(tmp->nCount) ;
}
}
// 如果树为空的话
if (m_pRoot == m_pSentinel)
{
tmp = new AberrTreeNode(_nAddr) ;
if (tmp == NULL)
{
exit(EXIT_FAILURE) ;
}
memset(tmp->szDump, 0, sizeof(char) * DUMPSIZE) ;
tmp->SetDump(pDump, sizeof(char) * nLen) ;
tmp->left = tmp->right = tmp->parent = m_pSentinel ;
tmp->color = b_red ;
m_pRoot = tmp ;
if (InsertLink(tmp))
{
return tmp ;
}
else
{
return 0 ;
}
}
for (; pNode != m_pSentinel;)
{
if (_nAddr <= pNode->nAddress && pNode->left != m_pSentinel)
{
pNode = pNode->left ;
}
else if (_nAddr > pNode->nAddress && pNode->right != m_pSentinel)
{
pNode = pNode->right ;
}
else if (_nAddr == pNode->nAddress)
{
pNode = m_pSentinel ;
}
else
{
break ;
}
}
if (pNode == m_pSentinel)
{
return 0;
}
tmp = NULL ;
tmp = new AberrTreeNode(_nAddr) ;
if (tmp == NULL)
{
exit(EXIT_FAILURE) ;
}
memset(tmp->szDump, 0, sizeof(char) * DUMPSIZE) ;
tmp->SetDump(pDump, sizeof(char) * nLen) ;
tmp->left = tmp->right = m_pSentinel ;
tmp->color = b_red ;
tmp->parent = pNode ;
// 往左边插入
if (_nAddr <= pNode->nAddress && pNode->left == m_pSentinel)
{
pNode->left = tmp ;
}
// 入右边插入
else if (_nAddr > pNode->nAddress && pNode->right == m_pSentinel)
{
pNode->right = tmp ;
}
insertFixup(tmp) ;
if (InsertLink(tmp))
{
return tmp ;
}
else
{
return 0 ;
}
}
/*******************************************************************************
*
* 函 数 名 : Remove
* 功能描述 : 移除树中的指定节点
* 参数列表 : _nAddr -- 要移除的值
* 说 明 :
* 返回结果 : 如果移除了,返回1,否则返回0
*
*******************************************************************************/
int AberranceTree::Remove(IN unsigned int _nAddr)
{
return Delete(m_pRoot, _nAddr) ;
}
/*******************************************************************************
*
* 函 数 名 : Destory
* 功能描述 : 销毁整棵树
* 参数列表 : T -- 树的根结点
* 说 明 :
* 返回结果 :
*
*******************************************************************************/
void AberranceTree::Destory(IN AberrTreeNode *T)
{
if (T != m_pSentinel && T != NULL )
{
Destory(T->left) ;
Destory(T->right) ;
}
}
/*******************************************************************************
*
* 函 数 名 : FindMin
* 功能描述 : 查找树中最小的节点
* 参数列表 : T -- 树的根结点
* 说 明 :
* 返回结果 : 如果成功返回指向该树中最小节点的指针,否则返回NULL
*
*******************************************************************************/
AberrTreeNode * AberranceTree::FindMin(IN AberrTreeNode * T)
{
if (m_pRoot == m_pSentinel || T == m_pSentinel)
{
return NULL ;
}
while (T->left != m_pSentinel )
{
T = T->left ;
}
return T ;
}
/*******************************************************************************
*
* 函 数 名 : FindMax
* 功能描述 : 查找树中最大的节点
* 参数列表 : T -- 树的根结点
* 说 明 :
* 返回结果 : 如果成功返回指向该树中最大节点的指针,否则返回NULL
*
*******************************************************************************/
AberrTreeNode * AberranceTree::FindMax(IN AberrTreeNode * T)
{
if (m_pRoot == m_pSentinel || T == m_pSentinel)
{
return NULL ;
}
while (T->right != m_pSentinel )
{
T = T->right ;
}
return T ;
}
/*******************************************************************************
*
* 函 数 名 : getGrandParent
* 功能描述 : 查找指定节点的祖父节点
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 如果成功返回指向该节的祖父结点
*
*******************************************************************************/
AberrTreeNode * AberranceTree::getGrandParent(IN const AberrTreeNode * pNode)
{
if (pNode != m_pSentinel && pNode->parent != m_pSentinel)
{
return pNode->parent->parent ;
}
return m_pSentinel ;
}
/*******************************************************************************
*
* 函 数 名 : getUncle
* 功能描述 : 查找指定节点的叔叔结点
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 如果成功返回指向该节点的叔叔结点
*
*******************************************************************************/
AberrTreeNode * AberranceTree::getUncle(IN const AberrTreeNode * pNode)
{
AberrTreeNode * p = getGrandParent(pNode) ;
if (p == m_pSentinel)
{
return m_pSentinel ;
}
if (p->left == pNode->parent)
{
return p->right ;
}
else
{
return p->left ;
}
return m_pSentinel ;
}
/*******************************************************************************
*
* 函 数 名 : getSibling
* 功能描述 : 查找指定节点的兄弟结点
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 如果成功返回指向该节点的兄弟结点
*
*******************************************************************************/
AberrTreeNode * AberranceTree::getSibling(IN const AberrTreeNode * pNode)
{
if (pNode == m_pSentinel || pNode->parent == m_pSentinel || pNode == m_pRoot)
{
return m_pSentinel ;
}
if (pNode->parent->left == pNode)
{
return pNode->parent->right ;
}
else
{
return pNode->parent->left ;
}
return m_pSentinel ;
}
/*******************************************************************************
*
* 函 数 名 : insertFixup
* 功能描述 : 插入着色
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 无
*
*******************************************************************************/
void AberranceTree::insertFixup(IN AberrTreeNode * pNode)
{
if (pNode == m_pSentinel)
{
return; // impossible actually.
}
AberrTreeNode * pUncle = m_pSentinel;
AberrTreeNode * pGrandParent = NULL;
while (pNode != m_pRoot && b_red == pNode->parent->color)
{
pUncle = getUncle(pNode);
pGrandParent = getGrandParent(pNode);
if (pUncle != NULL && pUncle != m_pSentinel && pUncle->color == b_red)
{
pNode->parent->color = b_black;
pUncle->color = b_black;
pGrandParent->color = b_red;
pNode = pGrandParent;
}
else
{
if (pNode->parent == pGrandParent->left)
{
if (pNode == pNode->parent->right)
{
pNode = pNode->parent;
rotateLeft(pNode);
}
pNode->parent->color = b_black;
pGrandParent->color = b_red;
rotateRight(pGrandParent);
}
else
{
if (pNode == pNode->parent->left)
{
pNode = pNode->parent;
rotateRight(pNode);
}
pNode->parent->color = b_black;
pGrandParent->color = b_red;
rotateLeft(pGrandParent);
}
}
}
m_pRoot->color = b_black;
}
/*******************************************************************************
*
* 函 数 名 : removeFixup
* 功能描述 : 移除着色
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 无
*
*******************************************************************************/
void AberranceTree::removeFixup(IN AberrTreeNode * pNode)
{
AberrTreeNode * pSibling = NULL;
while ((pNode != m_pRoot) && (pNode->color == b_black))
{
pSibling = getSibling(pNode);
if (pNode == pNode->parent->left) // left child node
{
if (pSibling->color == b_red)
{
// case 1, can change to case 2, 3, 4
pNode->parent->color = b_red;
pSibling->color = b_black;
rotateLeft(pNode->parent);
// change to new sibling,
pSibling = pNode->parent->right;
}
// case 2;
if ((b_black == pSibling->left->color) && (b_black == pSibling->right->color))
{
pSibling->color = b_red;
pNode = pNode->parent;
}
else
{
if (b_black == pSibling->right->color)
{
pSibling->color = b_red;
pSibling->left->color = b_black;
rotateRight(pSibling);
pSibling = pNode->parent->right;
}
pSibling->color = pNode->parent->color;
pNode->parent->color = b_black;
pSibling->right->color = b_black;
rotateLeft(pNode->parent);
break;
}
}
else
{
if (pSibling->color == b_red)
{
// case 1, can change to case 2, 3, 4
pNode->parent->color = b_red;
pSibling->color = b_black;
rotateRight(pNode->parent);
// change to new sibling,
pSibling = pNode->parent->left;
}
// case 2;
if ((b_black == pSibling->left->color) && (b_black == pSibling->right->color))
{
pSibling->color = b_red;
pNode = pNode->parent;
}
else
{
if (b_black == pSibling->left->color)
{
pSibling->color = b_red;
pSibling->right->color = b_black;
rotateLeft(pSibling);
pSibling = pNode->parent->left;
}
pSibling->color = pNode->parent->color;
pNode->parent->color = b_black;
pSibling->left->color = b_black;
rotateRight(pNode->parent);
break;
}
}
}
pNode->color = b_black;
}
/*******************************************************************************
*
* 函 数 名 : rotateLeft
* 功能描述 : 左旋转
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 无
*
*******************************************************************************/
void AberranceTree::rotateLeft(IN AberrTreeNode * pNode)
{
if (pNode == m_pSentinel || pNode == NULL || pNode->right == m_pSentinel \
|| pNode->right == NULL)
{
return ;
}
AberrTreeNode * x = pNode ;
AberrTreeNode * y = pNode->right ;
x->right = y->left ;
if (y->left != m_pSentinel)
{
y->left->parent = x ;
}
y->left = x ;
y->parent = x->parent ;
x->parent = y ;
if (x == y->parent->left)
{
y->parent->left = y ;
}
else
{
y->parent->right = y ;
}
if (pNode == m_pRoot)
{
m_pRoot = y ;
}
return ;
}
/*******************************************************************************
*
* 函 数 名 : rotateRight
* 功能描述 : 右旋转
* 参数列表 : pNode -- 树的节点
* 说 明 :
* 返回结果 : 无
*
*******************************************************************************/
void AberranceTree::rotateRight(IN AberrTreeNode * pNode)
{
if (pNode == m_pSentinel || pNode->left == m_pSentinel)
{
return ;
}
AberrTreeNode * x = pNode->left ;
AberrTreeNode * y = pNode ;
y->left = x->right ;
if (x->right != m_pSentinel)
{
x->right->parent = y ;
}
x->right = y ;
x->parent = y->parent ;
y->parent = x ;
if (y == x->parent->left)
{
x->parent->left = x ;
}
else
{
x->parent->right = x ;
}
if (pNode == m_pRoot)
{
m_pRoot = x ;
}
return ;
}
// 先
void AberranceTree::Preorder(void)
{
preorder(m_pRoot) ;
}
// 后
void AberranceTree::Postorder(void)
{
postorder(m_pRoot) ;
}
// 中
void AberranceTree::Inorder(void)
{
inorder(m_pRoot) ;
}
void AberranceTree::inorder(IN AberrTreeNode * T)
{
if (T != m_pSentinel)
{
inorder(T->left) ;
printf("%p ", T->nAddress) ;
for (int i = 0; i < 12; ++i)
{
printf("%02X", T->szDump[i]) ;
}
printf(" %6s %p\r\n", ((T->color == b_red)? "red":"black"), T->jmpconst) ;
inorder(T->right) ;
}
}
void AberranceTree::postorder(IN AberrTreeNode * T)
{
if (T != m_pSentinel)
{
postorder(T->left) ;
postorder(T->right) ;
printf("%p ", T->nAddress) ;
for (int i = 0; i < 12; ++i)
{
printf("%02X", T->szDump[i]) ;
}
printf(" %6s %p\r\n", ((T->color == b_red)? "red":"black"), T->jmpconst) ;
}
}
void AberranceTree::preorder(IN AberrTreeNode * T)
{
if (T != m_pSentinel)
{
printf("%p ", T->nAddress) ;
for (int i = 0; i < 12; ++i)
{
printf("%02X", T->szDump[i]) ;
}
printf(" %6s %p\r\n", ((T->color == b_red)? "red":"black"), T->jmpconst) ;
preorder(T->left) ;
preorder(T->right) ;
}
}
/*******************************************************************************
*
* 函 数 名 : Delete
* 功能描述 : 删除指定节点
* 参数列表 : T -- 指向树的指针
nAddress -- 要删除节点的值
* 说 明 :
* 返回结果 : 如果函数执行成功返回1,否则返回0
*
*******************************************************************************/
int AberranceTree::Delete(IN AberrTreeNode *T, IN unsigned int nAddress)
{
if (T == NULL || T == m_pSentinel)
{
return 0;
}
while(T != m_pSentinel)
{
if (nAddress < T->nAddress)
{
T = T->left ;
}
else if (nAddress > T->nAddress)
{
T = T->right ;
}
else
{
break ;
}
}
if (T == m_pSentinel)
{
return 0;
}
if (T->left != m_pSentinel && T->right != m_pSentinel)
{
AberrTreeNode * p = FindMin(T->right) ;
if (p != m_pSentinel && p != NULL)
{
T->nAddress = p->nAddress;
Delete(T->right, T->nAddress) ;
}
}
// 只有左儿子
else if (T->left)
{
AberrTreeNode * p = T ;
if (m_pRoot == T)
{
m_pRoot = T->left ;
m_pRoot->parent = m_pSentinel ;
delete T ;
}
else
{
T->left->parent = T->parent ;
if (T->parent->left == T)
{
T->parent->left = T->left ;
}
else
{
T->parent->right = T->left ;
}
delete p ;
}
}
else if (T->right)
{
if (m_pRoot == T)
{
m_pRoot = T->left ;
m_pRoot->parent = m_pSentinel ;
delete T ;
}
else
{
AberrTreeNode * p = T ;
T->right->parent = T->parent ;
if (T->parent->left == T)
{
T->parent->left = T->right ;
}
else
{
T->parent->right = T->right ;
}
delete p ;
}
}
return 1 ;
}
/*******************************************************************************
*
* 函 数 名 : Clear
* 功能描述 : 清空树
* 参数列表 : 无
* 说 明 :
* 返回结果 : 成功返回1,失败返回0
*
*******************************************************************************/
int AberranceTree::Clear()
{
if (m_pRoot != m_pSentinel)
{
Destory(m_pRoot) ;
m_pRoot = NULL ;
}
if (m_pSentinel != NULL)
{
delete m_pSentinel ;
m_pSentinel = NULL ;
}
m_pSentinel = new AberrTreeNode ;
if (m_pSentinel == NULL)
{
exit(EXIT_FAILURE) ;
}
m_pSentinel->color = b_black ;
m_pSentinel->left = m_pSentinel ;
m_pSentinel->right = m_pSentinel ;
m_pSentinel->parent = m_pSentinel ;
m_pRoot = m_pSentinel ;
m_pHead = NULL ;
m_pLast = NULL ;
return 1 ;
}
/*******************************************************************************
*
* 函 数 名 : Find
* 功能描述 : 查找
* 参数列表 : 无
* 说 明 :
* 返回结果 : 成功返回树的节点,失败返回NULL
*
*******************************************************************************/
AberrTreeNode * AberranceTree::Find(IN unsigned int _nAddr)
{
AberrTreeNode * p = m_pRoot ;
for(;m_pSentinel != p;)
{
if (_nAddr == p->nAddress)
{
return p ;
}
else if (_nAddr < p->nAddress)
{
p = p->left ;
}
else
{
p = p->right ;
}
}
return NULL ;
}
/*******************************************************************************
*
* 函 数 名 : FindEx
* 功能描述 : 扩展查找
* 参数列表 : 无
* 说 明 :
* 返回结果 : 成功返回树的节点,失败返回NULL
*
*******************************************************************************/
AberrTreeNode * AberranceTree::FindEx(IN unsigned int _nAddr,
IN char *pSzDump,
IN int nInstrLen)
{
AberrTreeNode * p = m_pRoot ;
for(;m_pSentinel != p;)
{
if (_nAddr == p->nAddress && 0 == memcmp(p->szDump, pSzDump,
sizeof(char) * nInstrLen))
{
return p ;
}
else if (_nAddr < p->nAddress)
{
p = p->left ;
}
else
{
p = p->right ;
}
}
return NULL ;
}
/*******************************************************************************
*
* 函 数 名 : SetDump
* 功能描述 : 设置Dump数据
* 参数列表 : 无
* 说 明 :
* 返回结果 : 成功返回树的节点,失败返回NULL
*
*******************************************************************************/
int AberrTreeNode::SetDump(IN char *pDump, IN int nLen)
{
if (NULL == this)
{
return 0 ;
}
if (NULL == pDump)
{
return 0 ;
}
memset(szDump, 0, sizeof(char)*DUMPSIZE) ;
memcpy(szDump, pDump, sizeof(char) * nLen ) ;
return 1 ;
}
/*******************************************************************************
*
* 函 数 名 : DisplayLink
* 功能描述 : 输出链表
* 参数列表 : 无
* 说 明 :
* 返回结果 : 成功返回树的节点,失败返回NULL
*
*******************************************************************************/
int AberranceTree::DisplayLink()
{
if (NULL == m_pHead)
{
return 0 ;
}
AberrTreeNode *p = m_pHead ;
for (; p != NULL; p = p->pNext)
{
printf("%p ", p->nAddress) ;
for (int i = 0; i < 12; ++i)
{
printf("%02X", p->szDump[i]) ;
}
printf(" %6s %p\r\n", ((p->color == b_red)? "red":"black"), p->jmpconst) ;
}
return 1 ;
}
/*******************************************************************************
*
* 函 数 名 : InsertLink
* 功能描述 : 将树的结点加到链表中去
* 参数列表 : 无
* 说 明 :
* 返回结果 : 成功返回树的节点,失败返回NULL
*
*******************************************************************************/
int AberranceTree::InsertLink(IN AberrTreeNode *p)
{
if (NULL == p)
{
return 0 ;
}
// 往链表里插
// 如果链表是空的话
if (NULL == m_pHead)
{
m_pHead = p ;
m_pLast = p ;
}
// 否则往尾部插
else
{
m_pLast->pNext = p ;
m_pLast = p ;
}
return 1 ;
}
/*******************************************************************************
*
* 函 数 名 : GetListHead
* 功能描述 : 取得链表头结点
* 参数列表 : 无
* 说 明 :
* 返回结果 : 链表的头结点
*
*******************************************************************************/
AberrTreeNode * AberranceTree::GetListHead()
{
return m_pHead ;
}