コード例 #1
0
ファイル: main.cpp プロジェクト: Hitesh-jaarwis/DFS
int BinarySearchTree :: breadthFirstTraversal (int number) const {
    
    Queue queue;
    BSTNode* current = root;
    queue.add(root);
    int count = 0;
    while (current != NULL) {
        
        //If there is right child, add it to queue
        if (current -> getLeft() != 0)
            queue.add(current -> getLeft());
        
        //If there is right child, add it to queue
        if (current -> getRight() != 0)
            queue.add(current -> getRight());
        
        queue.removeFromHead(current);
        if (current->getValue() == number) {
            return count;
        }
        current = getBSTNodeFromQueue(queue);
        count++;
    }
    return count;
}// end breadthFirstTraversal
コード例 #2
0
ファイル: main.cpp プロジェクト: Hitesh-jaarwis/DFS
void UnorderedLinkedList :: print () const {
    
    
    
    //    cout<< "(" << ((left == 0)?0:left -> getValue())  <<")";
    //    cout<<value;
    //    cout<< "(" << ((right == 0)?0:right -> getValue())<<")";
    //    cout<<endl;
    
    
    
    if (head != 0) {
        BSTNode *nodeHead = head -> getValue ();
        cout<< "Head -->" << ((head == 0)?0:nodeHead->getValue());
    }
    cout<<endl;
    if (tail != 0) {
        BSTNode *nodeTail = tail -> getValue ();
        cout<< "Tail -->" << ((tail == 0)?0:nodeTail->getValue());
    }
    cout<<endl;
    
}//end print