Exemplo n.º 1
0
void SplayTree::insert(int key) {
	
	if (size == maxSize) {
		removeLeastUsed();
	}
	
	TreeNode *temp = root;
	TreeNode *p = 0;

	while (temp) {
		p = temp;

		if (temp->key < key) {
			temp = temp->right;
		} else {
			temp = temp->left;
		}
	}

	temp = new TreeNode(p);
	temp->key = key;

	if (!p) {
		root = temp;
	} else if (p->key < temp->key) {
		p->right = temp;
	} else {
		p->left = temp;
	}

	splay(temp);

	size++;
}
Exemplo n.º 2
0
void SplayTree::setMaxSize(int newMaxSize) {
	maxSize = newMaxSize;

	while (maxSize < size) {
		removeLeastUsed();
	}
}
    void appendNew(const KoColor& data) {
        if (size() >= ColorDataList::MAX_RECENT_COLOR) removeLeastUsed();

        PriorityNode<KoColor> * node;
        node = new PriorityNode <KoColor>();
        node->data = data;
        node->key = m_key++;
        m_priorityList.append(node);

        int pos = guiInsertPos(data);
        pos >= m_guiList.size() ? m_guiList.append(node)
        : m_guiList.insert(pos, node);
        node = 0;
    }