1. 程式人生 > >C++之map的資料結構表示

C++之map的資料結構表示

●關聯容器(也是ADT 抽象資料型別)

  map,set,multiset,multimap
●有序容器
  vector,list


1.std::map底層的資料結構為平衡二叉樹(紅黑樹)進行實現。
2.二叉搜尋樹結構(程式碼)
class Node:
    def __init__(self, data,color,parent):
        self.left = None
        self.right = None
        self.data = data
self.parent = parent
self.color = color
class Tree:
    def __init__(self,compare):
        self.root = None
        self.node_count = 0
self.key_compare = compare


●遍歷抽象化
def visit(node, func):
    if node:
        printTree(node.left)
        func(node.data)
        printTree(node.right)