简体   繁体   中英

Creating a data structure that consists of a linked balanced bst and a doubly linked list

I am trying to create a data structure in which there is a balanced BST and a doubly linked list.The linked list will be smaller than BST and hence at any time will hold only a subset of elements from BST.Each Node of LL will point to its corresponding node in BST, and the BST node will point to its LL Node if the node is present in linked list otherwise it will store null.

To create this data structure I was planning to use std::set< data, std::list::iterator > for BST and std::list< data,std::set::iterator > for doubly linked list.Is it fine if I store the reference to each others element iterator to do this.Is there any chance that the set might do balancing and inturn invalidate the iterators held by linked list.Can there be any other problems with approach ?

How can I use STL or any other library to do this in C++ ?

( I wanted to create this Data structure to create a LRU cache)

std::set iterators remain valid when you insert new elements in the set, so this should not cause problems when you keep the iterators in a list. Erasing elements from the set will invalidate iterators to those elements (obviously), but other iterators remain valid.

Balanced binary search tree with a doubly linked list in C++

is here:

http://archive.gamedev.net/archive/reference/programming/features/TStorage/index.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM