From 94a494edf59a99ec0457e7fa264e7d17b4c5c6ce Mon Sep 17 00:00:00 2001 From: Krishna Vedala <7001608+kvedala@users.noreply.github.com> Date: Wed, 24 Jun 2020 10:27:23 -0400 Subject: [PATCH] replace NULL with nullptr --- data_structures/stack.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/data_structures/stack.h b/data_structures/stack.h index 3957b4d8d..31a5abe34 100644 --- a/data_structures/stack.h +++ b/data_structures/stack.h @@ -20,7 +20,7 @@ class stack { void display() { node *current = stackTop; std::cout << "Top --> "; - while (current != NULL) { + while (current != nullptr) { std::cout << current->data << " "; current = current->next; } @@ -30,7 +30,7 @@ class stack { /** Default constructor*/ stack() { - stackTop = NULL; + stackTop = nullptr; size = 0; } @@ -39,23 +39,23 @@ class stack { node *newNode, *current, *last; /* If stack is no empty, make it empty */ - if (stackTop != NULL) { - stackTop = NULL; + if (stackTop != nullptr) { + stackTop = nullptr; } - if (otherStack.stackTop == NULL) { - stackTop = NULL; + if (otherStack.stackTop == nullptr) { + stackTop = nullptr; } else { current = otherStack.stackTop; stackTop = new node; stackTop->data = current->data; - stackTop->next = NULL; + stackTop->next = nullptr; last = stackTop; current = current->next; /* Copy the remaining stack */ - while (current != NULL) { + while (current != nullptr) { newNode = new node; newNode->data = current->data; - newNode->next = NULL; + newNode->next = nullptr; last->next = newNode; last = newNode; current = current->next; @@ -68,7 +68,7 @@ class stack { ~stack() {} /** Determine whether the stack is empty */ - bool isEmptyStack() { return (stackTop == NULL); } + bool isEmptyStack() { return (stackTop == nullptr); } /** Add new item to the stack */ void push(Type item) { @@ -82,7 +82,7 @@ class stack { /** Return the top element of the stack */ Type top() { - assert(stackTop != NULL); + assert(stackTop != nullptr); return stackTop->data; } @@ -100,30 +100,30 @@ class stack { } /** Clear stack */ - void clear() { stackTop = NULL; } + void clear() { stackTop = nullptr; } /** Overload "=" the assignment operator */ stack &operator=(const stack &otherStack) { node *newNode, *current, *last; /* If stack is no empty, make it empty */ - if (stackTop != NULL) { - stackTop = NULL; + if (stackTop != nullptr) { + stackTop = nullptr; } - if (otherStack.stackTop == NULL) { - stackTop = NULL; + if (otherStack.stackTop == nullptr) { + stackTop = nullptr; } else { current = otherStack.stackTop; stackTop = new node; stackTop->data = current->data; - stackTop->next = NULL; + stackTop->next = nullptr; last = stackTop; current = current->next; /* Copy the remaining stack */ - while (current != NULL) { + while (current != nullptr) { newNode = new node; newNode->data = current->data; - newNode->next = NULL; + newNode->next = nullptr; last->next = newNode; last = newNode; current = current->next;