設計演算法,將n個資料組成二叉排序樹結構,並可以刪除其中的乙個結點。
輸入:資料個數n、n個資料、需要刪除的數值value。
輸出:原始資料、二叉排序樹的中序輸出及刪除結點value後的結果。
#includeusing namespace std;
template struct btnode;
template void createbintree(btnode* & root,int t)
else if(tdata)
else if(t>root->data)
}
template void inorder(btnode* & p)
} templateint delete(btnode* & root,int t)
else
} else return 0;
}
int main()
二叉排序樹
在複習資料結構,把這個東西總結一下。這種結構是動態查詢表,這種動態是相對靜態查詢 順序查詢,折半查詢,分塊查詢等 來說的。對於各種靜態鍊錶,要達到查詢複雜度為o logn 必須要求有序 而要使插入刪除複雜度為o 1 必須是鍊錶儲存。動態查詢表就可以同時滿足這兩者。動態查詢表的特點是表結構本身在查詢過...
二叉排序樹
name 二叉排序樹相關操作 author unimen date 2011 10 8 13 14 21 刪除結點比較麻煩,總結如下 4大種情況 1 結點p無右孩子 將該點的左孩子變為其在雙親中的同位孩子 1 p為其雙親的左孩子時將其的左孩子變為雙親的左孩子 2 p為其雙親的右孩子時將其的左孩子變為...
二叉排序樹
include include include include struct tree node void insert node struct tree node int void pre order struct tree node void in order struct tree node ...