Commit ed57554e authored by Anne Gunn's avatar Anne Gunn
Browse files

T2345: Replace instances of NULL with nullptr

revert lib/poems to remove nullptr changes.
Walking back changes to lib as needed.
parent f524fa75
Loading
Loading
Loading
Loading
+15 −15
Original line number Diff line number Diff line
@@ -110,21 +110,21 @@ void SystemProcessor::processArray(int** links, int numLinks)
        do
        {
                currentNode = findSingleLink(temp);                                             //find the start of the next available chain
                if(currentNode != nullptr)
                if(currentNode != NULL)
                {
                        headsOfSystems.Append(AddNewChain(currentNode));                                                        //and add it to the headsOfSystems list of chains
                }
        }
        while(currentNode != nullptr);                                                                     //repeat this until all chains have been added
        while(currentNode != NULL);                                                                     //repeat this until all chains have been added
}

POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){
        if(currentNode == nullptr) //Termination condition; if the currentNode is null, then return null
        if(currentNode == NULL) //Termination condition; if the currentNode is null, then return null
        {
                return nullptr;
                return NULL;
        }
        int * tmp;
        POEMSNode * nextNode = nullptr;    //nextNode stores the proposed next node to add to the chain.  this will be checked to make sure no backtracking is occurring before being assigned as the current node.
        POEMSNode * nextNode = NULL;    //nextNode stores the proposed next node to add to the chain.  this will be checked to make sure no backtracking is occurring before being assigned as the current node.
        POEMSChain * newChain = new POEMSChain; //make a new POEMSChain object.  This will be the object returned

        if(currentNode->links.GetNumElements() == 0)    //if we have no links from this node, then the whole chain is only one node.  Add this node to the chain and return it; mark node as visited for future reference
@@ -168,8 +168,8 @@ POEMSChain * SystemProcessor::AddNewChain(POEMSNode * currentNode){
        newChain->listOfNodes.Append(tmp);              //append the last node before branch (node shared jointly with branch chains)
                                                                                                                                //re-mark as visited, just to make sure
        ListElement<POEMSNode> * tempNode = currentNode->links.GetHeadElement();        //go through all of the links, one at a time that branch
        POEMSChain * tempChain = nullptr;                                                          //temporary variable to hold data
        while(tempNode != nullptr)                                                                         //when we have followed all links, stop
        POEMSChain * tempChain = NULL;                                                          //temporary variable to hold data
        while(tempNode != NULL)                                                                         //when we have followed all links, stop
        {
                if(setLinkVisited(tempNode->value, currentNode))                //dont backtrack, or create closed loops
                {
@@ -187,12 +187,12 @@ POEMSNode * SystemProcessor::findSingleLink(TreeNode * aNode)
//This function takes the root of a search tree containing POEMSNodes and returns a POEMSNode corresponding to the start of a chain in the
//system.  It finds a node that has not been visited before, and only has one link; this node will be used as the head of the chain.
{
        if(aNode == nullptr)
        if(aNode == NULL)
        {
                return nullptr;
                return NULL;
        }
        POEMSNode * returnVal =  (POEMSNode *)aNode->GetAuxData();      //get the poemsnode data out of the treenode
        POEMSNode * detectLoneLoops = nullptr;                                                     //is used to handle a loop that has no protruding chains
        POEMSNode * detectLoneLoops = NULL;                                                     //is used to handle a loop that has no protruding chains
        if(returnVal->visited == false)
        {
                detectLoneLoops = returnVal;                                                    //if we find any node that has not been visited yet, save it
@@ -202,15 +202,15 @@ POEMSNode * SystemProcessor::findSingleLink(TreeNode * aNode)
                return returnVal;                                                                                                               //return the node is it meets this criteria
        }
        returnVal = findSingleLink(aNode->Left());                                                                      //otherwise, check the left subtree
        if(returnVal == nullptr)                                                                                                           //and if we find nothing...
        if(returnVal == NULL)                                                                                                           //and if we find nothing...
        {
                returnVal = findSingleLink(aNode->Right());                                                             //check the right subtree
        }
        if(returnVal == nullptr)                                                                                                           //if we could not find any chains
        if(returnVal == NULL)                                                                                                           //if we could not find any chains
        {
                returnVal = detectLoneLoops;                                                                                    //see if we found any nodes at all that havent been processed
        }
        return returnVal;                                                                                                                       //return what we find (will be nullptr if no new chains are
        return returnVal;                                                                                                                       //return what we find (will be NULL if no new chains are
                                                                                                                                                                //found)
}

@@ -226,7 +226,7 @@ bool SystemProcessor::setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNo
        //cout << "Checking link between nodes " << firstNode->idNumber << " and " << secondNode->idNumber << "... ";
        ListElement<POEMSNode> * tmp = firstNode->links.GetHeadElement();       //get the head element of the list of pointers for node 1
        ListElement<bool> * tmp2 = firstNode->taken.GetHeadElement();           //get the head element of the list of bool isVisited flags for node 1
        while(tmp->value != nullptr || tmp2->value != nullptr)                                        //go through until we reach the end of the lists
        while(tmp->value != NULL || tmp2->value != NULL)                                        //go through until we reach the end of the lists
        {
                if(tmp->value == secondNode)                                                    //if we find the link to the other node
                {
@@ -248,7 +248,7 @@ bool SystemProcessor::setLinkVisited(POEMSNode * firstNode, POEMSNode * secondNo
        tmp = secondNode->links.GetHeadElement();                       //now, if the link was unvisited, we need to go set the other node's list such that
                                                                                                                //it also knows this link is being visited
        tmp2 = secondNode->taken.GetHeadElement();
        while(tmp->value != nullptr || tmp2->value != nullptr)        //go through the list
        while(tmp->value != NULL || tmp2->value != NULL)        //go through the list
        {
                if(tmp->value == firstNode)                                             //if we find the link
                {
+10 −10
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
using namespace std;


TreeNode *GetTreeNode(int item,TreeNode *lptr = nullptr,TreeNode *rptr =nullptr);
TreeNode *GetTreeNode(int item,TreeNode *lptr = NULL,TreeNode *rptr =NULL);

void FreeTreeNode(TreeNode *p);

@@ -46,7 +46,7 @@ void PrintTree (TreeNode *t, int level);
void Postorder (TreeNode *t, void visit(TreeNode* &t))
{
        // the recursive scan terminates on a empty subtree
        if (t != nullptr)
        if (t != NULL)
        {
                Postorder(t->Left(), visit);    // descend left
                Postorder(t->Right(), visit);   // descend right
@@ -59,7 +59,7 @@ void Postorder (TreeNode *t, void visit(TreeNode* &t))
void Preorder (TreeNode *t, void visit(TreeNode* &t))
{
        // the recursive scan terminates on a empty subtree
        if (t != nullptr)
        if (t != NULL)
        {
                visit(t);                               // visit the node
                Preorder(t->Left(), visit);             // descend left
@@ -69,7 +69,7 @@ void Preorder (TreeNode *t, void visit(TreeNode* &t))


//create TreeNode object with pointer fields lptr and rptr
// The pointers have default value nullptr
// The pointers have default value NULL
TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr)
{
        TreeNode *p;
@@ -79,7 +79,7 @@ TreeNode *GetTreeNode(int item,TreeNode *lptr,TreeNode *rptr)
        p = new TreeNode(item, lptr, rptr);

        // if insufficient memory, terminatewith an error message
        if (p == nullptr)
        if (p == NULL)
        {
                cerr << "Memory allocation failure!\n";
                exit(1);
@@ -103,14 +103,14 @@ void FreeTreeNode(TreeNode *p)
void CountLeaf (TreeNode *t, int& count)
{
        //use postorder descent
        if(t !=nullptr)
        if(t !=NULL)
        {
                CountLeaf(t->Left(), count); // descend left
                CountLeaf(t->Right(), count); // descend right

                // check if node t is a leaf node (no descendants)
                // if so, increment the variable count
                if (t->Left() == nullptr && t->Right() == nullptr)
                if (t->Left() == NULL && t->Right() == NULL)
                        count++;
        }
}
@@ -124,7 +124,7 @@ int Depth (TreeNode *t)
{
        int depthLeft, depthRight, depthval;

        if (t == nullptr)
        if (t == NULL)
                depthval = -1;
        else
        {
@@ -145,8 +145,8 @@ void IndentBlanks(int num)

void PrintTree (TreeNode *t, int level)
{
        //print tree with root t, as long as t!=nullptr
        if (t != nullptr)
        //print tree with root t, as long as t!=NULL
        if (t != NULL)
        {
                int indentUnit = 5;
                // print right branch of tree t
+31 −31
Original line number Diff line number Diff line
@@ -82,7 +82,7 @@ public:
      DeleteAuxData = callback;
    }

        void Insert(const int& item, const int& data, void * AuxData = nullptr);
        void Insert(const int& item, const int& data, void * AuxData = NULL);
        void Delete(const int& item);
        void AVLInsert(TreeNode* &tree, TreeNode* newNode, int &reviseBalanceFactor);
        void ClearList(void);
@@ -99,7 +99,7 @@ Tree::Tree(void)
        root = 0;
        current = 0;
        size = 0;
    DeleteAuxData = nullptr;
    DeleteAuxData = NULL;
}


@@ -131,18 +131,18 @@ Tree& Tree::operator = (const Tree& rhs)
}

// search for data item in the tree. if found, return its node
// address and a pointer to its parent; otherwise, return nullptr
// address and a pointer to its parent; otherwise, return NULL
TreeNode *Tree::FindNode(const int& item,
                                                                   TreeNode* & parent) const
{
        // cycle t through the tree starting with root
        TreeNode *t = root;

        // the parent of the root is nullptr
        parent = nullptr;
        // the parent of the root is NULL
        parent = NULL;

        // terminate on empty subtree
        while(t != nullptr)
        while(t != NULL)
        {
                // stop on a match
                if (item == t->data)
@@ -158,7 +158,7 @@ TreeNode *Tree::FindNode(const int& item,
                }
        }

        // return pointer to node; nullptr if not found
        // return pointer to node; NULL if not found
        return t;
}

@@ -172,14 +172,14 @@ void * Tree::Find(int& item)
        current = FindNode (item, parent);

        // if item found, assign data to item and return True
        if (current != nullptr)
        if (current != NULL)
        {
                item = current->data;
        return current->GetAuxData();
        }
        else
                // item not found in the tree. return False
                return nullptr;
                return NULL;
}


@@ -194,7 +194,7 @@ void Tree::Insert(const int& item, const int& data, void * AuxData)
        int reviseBalanceFactor = 0;

        // get a new AVL tree node with empty pointer fields
        newNode = GetTreeNode(item,nullptr,nullptr);
        newNode = GetTreeNode(item,NULL,NULL);
        newNode->data = data;
        newNode->SetAuxData(AuxData);
        // call recursive routine to actually insert the element
@@ -213,7 +213,7 @@ void Tree::AVLInsert(TreeNode *&tree, TreeNode *newNode, int &reviseBalanceFacto
        int rebalanceCurrNode;

        // scan reaches an empty tree; time to insert the new node
        if (tree == nullptr)
        if (tree == NULL)
        {
                // update the parent to point at newNode
                tree = newNode;
@@ -456,16 +456,16 @@ void Tree::Delete(const int& item)

        // search for a node containing data value item. obtain its
        // node address and that of its parent
        if ((DNodePtr = FindNode (item, PNodePtr)) == nullptr)
        if ((DNodePtr = FindNode (item, PNodePtr)) == NULL)
                return;

        // If D has nullptr pointer, the
        // If D has NULL pointer, the
        // replacement node is the one on the other branch
        if (DNodePtr->right == nullptr)
        if (DNodePtr->right == NULL)
                RNodePtr = DNodePtr->left;
        else if (DNodePtr->left == nullptr)
        else if (DNodePtr->left == NULL)
                RNodePtr = DNodePtr->right;
        // Both pointers of DNodePtr are non-nullptr
        // Both pointers of DNodePtr are non-NULL
        else
        {
                // Find and unlink replacement node for D
@@ -483,7 +483,7 @@ void Tree::Delete(const int& item)
                // descend down right subtree of the left child of D
                // keeping a record of current node and its parent.
                // when we stop, we have found the replacement
                while (RNodePtr->right != nullptr)
                while (RNodePtr->right != NULL)
                {
                        PofRNodePtr = RNodePtr;
                        RNodePtr = RNodePtr;
@@ -508,7 +508,7 @@ void Tree::Delete(const int& item)

        // complete the link to the parent node
        // deleting the root node. assign new root
        if (PNodePtr == nullptr)
        if (PNodePtr == NULL)
                root = RNodePtr;
        // attach R to the correct branch of P
        else if (DNodePtr->data < PNodePtr->data)
@@ -529,7 +529,7 @@ void Tree::Delete(const int& item)
// assign node value to item; otherwise, insert item in tree
void Tree::Update(const int& item)
{
        if (current !=nullptr && current->data == item)
        if (current !=NULL && current->data == item)
                current->data = item;
        else
                Insert(item, item);
@@ -545,25 +545,25 @@ TreeNode *Tree::CopyTree(TreeNode *t)
        TreeNode *newlptr, *newrptr, *newnode;

        // stop the recursive scan when we arrive at an empty tree
        if (t == nullptr)
                return nullptr;
        if (t == NULL)
                return NULL;

        // CopyTree builds a new tree by scanning the nodes of t.
        // At each node in t, CopyTree checks for a left child. if
        // present it makes a copy of left child or returns nullptr.
        // present it makes a copy of left child or returns NULL.
        // the algorithm similarly checks for a right child.
        // CopyTree builds a copy of node using GetTreeNode and
        // appends copy of left and right children to node.

        if (t->Left() !=nullptr)
        if (t->Left() !=NULL)
                newlptr = CopyTree(t->Left());
        else
                newlptr = nullptr;
                newlptr = NULL;

        if (t->Right() !=nullptr)
        if (t->Right() !=NULL)
                newrptr = CopyTree(t->Right());
        else
                newrptr = nullptr;
                newrptr = NULL;


        // Build new tree from the bottom up by building the two
@@ -579,12 +579,12 @@ TreeNode *Tree::CopyTree(TreeNode *t)
// the tree and delete each node at the visit operation
void Tree::DeleteTree(TreeNode *t)
{
  if (t != nullptr) {
  if (t != NULL) {
    DeleteTree(t->Left());
    DeleteTree(t->Right());
    void *aux = t->GetAuxData();
    if (aux != nullptr) {
      if (DeleteAuxData != nullptr) {
    if (aux != NULL) {
      if (DeleteAuxData != NULL) {
        (*DeleteAuxData)(aux);
      } else {
        delete (TreeNode *) aux;
@@ -595,11 +595,11 @@ void Tree::DeleteTree(TreeNode *t)
}

// call the function DeleteTree to deallocate the nodes. then
// set the root pointer back to nullptr
// set the root pointer back to NULL
void Tree::ClearTree(TreeNode * &t)
{
        DeleteTree(t);
        t = nullptr;               // root now nullptr
        t = NULL;               // root now NULL
}

// delete all nodes in list
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#include "poemstreenode.h"

// constructor; initialize the data and pointer fields
// The pointer value nullptr assigns a empty subtree
// The pointer value NULL assigns a empty subtree
TreeNode::TreeNode (const int & item, TreeNode *lptr,TreeNode *rptr,
					int balfac):data(item), left(lptr), right(rptr), balanceFactor(balfac)
{
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
#ifndef TREENODE_H
#define TREENODE_H

//#define nullptr 0
//#define NULL 0


//Tree depends on TreeNode
Loading