est Ci-dessous le code que j'ai créé qui teste bien pour afficher mes nœuds dans l'ordre croissant pour les noeuds plus supérieure ou égale à une valeur spécifiée. Quelqu'un peut-il s'il vous plaît examiner mon code et recommander des améliorations et si possible recommander comment je peux le faire pour ma méthode LessThan. Actuellement, ma méthode LessThan retourne dans l'ordre décroissant et je ne vois pas comment l'obtenir ascendante. À votre santé.
// --------------------------------------------------------------------------------
// GetNodesGreaterThan
// --------------------------------------------------------------------------------
/** \fn void RedBlackTree<T>::GetNodesGreaterThan(T &data)
* \brief This method checks to see if tree is empty otherwise calls the
* recursive the GreaterThan method.
* \param templated
* \return void
*/
template <class T>
void RedBlackTree<T>::GetNodesGreaterThan(T &data)
{
GreaterThan(m_root, data);
}
// --------------------------------------------------------------------------------
// GreaterThan
// --------------------------------------------------------------------------------
/** \fn void RedBlackTree<T>::GreaterThan(NodeType<T> *p, const T &data) const
* \brief This method finds the nodes in the tree that are greater than or equal to
* a specified value and puts nodes into a list.
* \param templated pointer
* \param constant template
* \return void
*/
template <class T>
void RedBlackTree<T>::GreaterThan(NodeType<T> *p, const T &data) const
{
if (p != NULL) // we have hit a leaf node
{
if ((p->m_data == data) || (data < p->m_data)){ // record the node whos value is
GreaterThan(p->m_lLink, data); // move down left link
//cout << p->m_data << " "; // Display data (debug purpose)
}
GreaterThan(p->m_rLink, data); // move down right link
}
}
// --------------------------------------------------------------------------------
// GetNodesLessThan
// --------------------------------------------------------------------------------
/** \fn void RedBlackTree<T>::GetNodesLessThan(T &data)
* \brief This method checks to see if tree is empty otherwise calls the
* recursive the LessThan method.
* \param template
* \return void
*/
template <class T>
void RedBlackTree<T>::GetNodesLessThan(T &data)
{
ClearList(); // clears the node list
LessThan(m_root, data);
}
// --------------------------------------------------------------------------------
// LessThan
// --------------------------------------------------------------------------------
/** \fn void RedBlackTree<T>::LessThan(NodeType<T> *p, const T &data) const
* \brief This method finds the nodes in the tree that are less than or equal to
* a specified value and puts nodes into a list.
* \param templated pointer
* \param constant template
*/
template <class T>
void RedBlackTree<T>::LessThan(NodeType<T> *p, const T &data) const
{
if (p != NULL)
{
if ((p->m_data == data) || (data > p->m_data)){ // record the node whos value is
LessThan(p->m_rLink, data); // move down left link
//cout << p->m_data << " "; // Display data (debug purpose)
//m_list[m_countOfElements] = p->m_data; // add to list
//m_countOfElements++; // increment # of elements
}
LessThan(p->m_lLink, data); // move down left link
}
}
Quelqu'un, je suis sûr que cette question a été manquée par les gourous là-bas? Veuillez revoir ma méthode LessThen et conseiller comment je peux obtenir les nœuds dans l'ordre croissant. –