formatting source-code for 153fb7b8a5

This commit is contained in:
github-actions
2020-05-30 04:02:09 +00:00
parent 92fe9495ec
commit 8a2de9842b
175 changed files with 1671 additions and 3460 deletions

View File

@@ -6,26 +6,21 @@ using namespace std;
/* Default constructor*/
template <class Type>
stack<Type>::stack()
{
stack<Type>::stack() {
stackTop = NULL;
size = 0;
}
/* Destructor */
template <class Type>
stack<Type>::~stack()
{
}
stack<Type>::~stack() {}
/* Display for testing */
template <class Type>
void stack<Type>::display()
{
void stack<Type>::display() {
node<Type> *current = stackTop;
cout << "Top --> ";
while (current != NULL)
{
while (current != NULL) {
cout << current->data << " ";
current = current->next;
}
@@ -35,22 +30,19 @@ void stack<Type>::display()
/* Determine whether the stack is empty */
template <class Type>
bool stack<Type>::isEmptyStack()
{
bool stack<Type>::isEmptyStack() {
return (stackTop == NULL);
}
/* Clear stack */
template <class Type>
void stack<Type>::clear()
{
void stack<Type>::clear() {
stackTop = NULL;
}
/* Add new item to the stack */
template <class Type>
void stack<Type>::push(Type item)
{
void stack<Type>::push(Type item) {
node<Type> *newNode;
newNode = new node<Type>;
newNode->data = item;
@@ -61,42 +53,35 @@ void stack<Type>::push(Type item)
/* Return the top element of the stack */
template <class Type>
Type stack<Type>::top()
{
Type stack<Type>::top() {
assert(stackTop != NULL);
return stackTop->data;
}
/* Remove the top element of the stack */
template <class Type>
void stack<Type>::pop()
{
void stack<Type>::pop() {
node<Type> *temp;
if (!isEmptyStack())
{
if (!isEmptyStack()) {
temp = stackTop;
stackTop = stackTop->next;
delete temp;
size--;
}
else
{
} else {
cout << "Stack is empty !" << endl;
}
}
/* Operator "=" */
template <class Type>
stack<Type> stack<Type>::operator=(stack<Type> &otherStack)
{
stack<Type> stack<Type>::operator=(stack<Type> &otherStack) {
node<Type> *newNode, *current, *last;
if (stackTop != NULL) /* If stack is no empty, make it empty */
stackTop = NULL;
if (otherStack.stackTop == NULL)
stackTop = NULL;
else
{
else {
current = otherStack.stackTop;
stackTop = new node<Type>;
stackTop->data = current->data;
@@ -104,8 +89,7 @@ stack<Type> stack<Type>::operator=(stack<Type> &otherStack)
last = stackTop;
current = current->next;
/* Copy the remaining stack */
while (current != NULL)
{
while (current != NULL) {
newNode = new node<Type>;
newNode->data = current->data;
newNode->next = NULL;