0001 #define PRINT(x) { \ 0002 print(x); \ 0003 printf("Sum ="); print(sum(x)); printf("\n"); \ 0004 int inversions = inv(x); \ 0005 printf((inversions < 1) ? "Sorted\n\n" : "%d Inversion(s)\n\n", inversions); \ 0006 } 0007 0008 #include <cstdio> //采用C风格精细控制输出格式 0009 #include "huffman/huffChar.h" //Huffman超字符 0010 #include "BinTree/BinTree.h" //二叉树 0011 #include "Huffman/HuffTree.h" //Huffman树 0012 #include "BST/BST.h" //二叉搜索树 0013 #include "AVL/AVL.h" //AVL树 0014 #include "Splay/Splay.h" //伸展树 0015 #include "redBlack/RedBlack.h" //红黑树 0016 #include "BTree/BTree.h" //二叉搜索树 0017 #include "Entry/Entry.h" //词条 0018 #include "Skiplist/Skiplist.h" //跳转表 0019 #include "Hashtable/Hashtable.h" //散列表 0020 #include "PQ_List/PQ_List.h" //基于列表实现的优先级队列 0021 #include "PQ_ComplHeap/PQ_ComplHeap.h" //基于完全堆实现的优先级队列 0022 #include "PQ_LeftHeap/PQ_LeftHeap.h" //基于左式堆实现的优先级队列 0023 #include "graph/Graph.h" //图 0024 #include "graphMatrix/GraphMatrix.h" //基于邻接矩阵实现的图 0025 0026 /****************************************************************************************** 0027 * 数据元素、数据结构通用输出接口 0028 ******************************************************************************************/ 0029 template <typename T> static void print(T* x) { x ? print(*x) : printf(" <nullptr>"); } 0030 template <typename T> static void print(T& x) { UniPrint::p(x); } 0031 template <typename T> static void print(const T& x) { UniPrint::p(x); } //for Stack 0032 static void print(char* x) { printf(" %s", x ? x : "<nullptr>"); } //字符串特别处理 0033 static void print(const char* x) { printf(" %s", x ? x : "<nullptr>"); } //字符串特别处理 0034 0035 class UniPrint { 0036 public: 0037 static void p(int); 0038 static void p(size_t); 0039 static void p(float); 0040 static void p(double); 0041 static void p(char); 0042 static void p(HuffChar&); //Huffman(超)字符 0043 static void p(VStatus); //图顶点的状态 0044 static void p(EType); //图边的类型 0045 0046 template <typename K, typename V> static void p(Entry<K,V>&); //Entry 0047 template <typename T> static void p(BinNode<T>& b) { p(&b); }; //BinTree节点 0048 template <typename T> static void p(BNP<T>); //BinTree节点 0049 template <typename T> static void p(BinTree<T>&); //二叉树 0050 template <typename T> static void p(BTree<T>&); //B-树 0051 template <typename T> static void p(BST<T>&); //BST 0052 template <typename T> static void p(AVL<T>&); //AVL 0053 template <typename T> static void p(RedBlack<T>&); //RedBlack 0054 template <typename T> static void p(Splay<T>&); //Splay 0055 template <typename T> static void p(Skiplist<T>&); //Skiplist 0056 template <typename K, typename V> static void p(Hashtable<K,V>&); //Hashtable 0057 template <typename T> static void p(ListPQ<T>&); //ListPQ 0058 template <typename T> static void p(ComplHeap<T>&); //ComplHeap 0059 template <typename T> static void p(LeftHeap<T>&); //LeftHeap 0060 template <typename Tv, typename Te> static void p(GraphMatrix<Tv, Te>&); //Graph 0061 template <typename T> static void p(T&); //向量、列表等支持traverse()遍历操作的线性结构 0062 template <typename T> static void p(T* s) //所有指针 0063 { s ? p(*s) : print("<nullptr>"); } //统一转为引用 0064 }; //UniPrint