00001
00002
00003
00004
00005
00006
00007
00008
00009 #include <stdlib.h>
00010 #include <stdio.h>
00011 #include "TestAVLRedBlackTree.h"
00012
00013 void Shuffle (int *Array, int n)
00014 {
00015 for (int i = 0; i < n; i++)
00016 {
00017 int j = i + rand () % (n - i);
00018 int t = Array[j];
00019 Array[j] = Array[i];
00020 Array[i] = t;
00021 }
00022 }
00023
00024 int RecurseTree (AVLRedBlackNode<int> *Node, int *Count, int GreaterEqual, int LessEqual, bool* Done)
00025 {
00026 if (Node)
00027 {
00028
00029 const int Data = *(Node->m_Data);
00030 int NodeLeft = 1;
00031 int NodeRight = 1;
00032
00033 (*Count)++;
00034
00035 if (!(Data >= GreaterEqual) || !(Data <= LessEqual))
00036 {
00037 printf (" Node %d is out of order in the tree.\n", Data);
00038 *Done = true;
00039 }
00040
00041 if (Node->m_Left)
00042 NodeLeft = RecurseTree(Node->m_Left, Count, GreaterEqual, Data - 1, Done);
00043 if (Node->m_Right)
00044 NodeRight = RecurseTree(Node->m_Right, Count, Data + 1, LessEqual, Done);
00045
00046 if (Node->m_Color != RED && Node->m_Color != BLACK)
00047 {
00048 printf (" Node %d is neither red nor black (%d).\n", Data, Node->m_Color);
00049 *Done = true;
00050 }
00051
00052 if ((Node->m_Color == RED) && (Node->m_Left) && (Node->m_Left->m_Color == RED))
00053 {
00054 printf (" Red node %d has red left child %d\n", Data, *(Node->m_Left->m_Data));
00055 *Done = true;
00056 }
00057
00058 if ((Node->m_Color == RED) && (Node->m_Right) && (Node->m_Right->m_Color == RED))
00059 {
00060 printf (" Red node %d has red right child %d\n", Data, *(Node->m_Right->m_Data));
00061 *Done = true;
00062 }
00063
00064 if (NodeLeft != NodeRight)
00065 {
00066 printf (" Node %d has two different black-heights: left bh=%d, " "right bh=%d\n", Data, NodeLeft, NodeRight);
00067 *Done = true;
00068 }
00069
00070 return (Node->m_Color == BLACK) + NodeLeft;
00071 }
00072
00073 return 1;
00074 }