Clean up old and new files
This commit is contained in:
@@ -51,7 +51,7 @@ int main()
|
||||
std::cin >> key;
|
||||
std::cin.clear();
|
||||
if (testList.insert(val, key)) {
|
||||
std::cout << "List after inserting ["
|
||||
std::cout << "List after inserting ["
|
||||
<< val << "] at [" << key << "]: \n";
|
||||
testList.print();
|
||||
}
|
||||
@@ -91,7 +91,7 @@ int main()
|
||||
std::cin >> key;
|
||||
std::cin.clear();
|
||||
if (testList.replace(val, key)) {
|
||||
std::cout << "List after replacing ["
|
||||
std::cout << "List after replacing ["
|
||||
<< key << "] by [" << val << "]: \n";
|
||||
testList.print();
|
||||
}
|
||||
|
||||
@@ -10,13 +10,14 @@
|
||||
|
||||
#include "singlelist.h"
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Constructors, Destructors, Operators
|
||||
*****************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
/** copy constructor
|
||||
* @brief Construct a new SingleList::SingleList object from an existing one
|
||||
*
|
||||
*
|
||||
* @param rhs SingleList object
|
||||
*/
|
||||
SingleList::SingleList(const SingleList& rhs)
|
||||
@@ -39,8 +40,8 @@ SingleList::SingleList(const SingleList& rhs)
|
||||
/** operator=
|
||||
* @brief Assign two SingleList objects equal using copy constr and class destr
|
||||
* Pass the rhs by value to create local copy, swap its contents
|
||||
* Destructor called on previous SingleList data at the end of this scope
|
||||
*
|
||||
* Destructor called on previous SingleList data at the end of this scope
|
||||
*
|
||||
* @param rhs SingleList object passed by value
|
||||
* @return SingleList A deep copy of the rhs SingleList object
|
||||
*/
|
||||
@@ -51,7 +52,7 @@ SingleList SingleList::operator=(SingleList rhs)
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
/** destructor
|
||||
* @brief Destroy the SingleList::SingleList object
|
||||
*/
|
||||
SingleList::~SingleList()
|
||||
@@ -59,19 +60,20 @@ SingleList::~SingleList()
|
||||
makeEmpty();
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Public Member Functions
|
||||
*****************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
/** insert
|
||||
* @brief Inserts a value to the head of our linked list
|
||||
*
|
||||
*
|
||||
* @param x The value to be inserted
|
||||
*/
|
||||
bool SingleList::insert(int val)
|
||||
{
|
||||
bool inserted = insert(val, head);
|
||||
if (inserted)
|
||||
if (inserted)
|
||||
std::cout << "[" << val << "] was inserted into the list\n";
|
||||
else std::cout << "[" << val << "] could not be inserted into the list\n";
|
||||
return inserted;
|
||||
@@ -80,14 +82,14 @@ bool SingleList::insert(int val)
|
||||
/** insert at
|
||||
* @brief Inserts a value in the place of a given key
|
||||
* Key Node found is moved to the newNode->next positon
|
||||
*
|
||||
*
|
||||
* @param key The value to search for to determine insert location
|
||||
* @param val The value to be inserted into the list
|
||||
*/
|
||||
bool SingleList::insert(int val, int key)
|
||||
{
|
||||
bool inserted = insert(val, key, head);
|
||||
if (inserted)
|
||||
if (inserted)
|
||||
std::cout << "[" << val << "] was inserted into the list\n";
|
||||
else std::cout << "[" << val << "] could not be inserted into the list\n";
|
||||
return inserted;
|
||||
@@ -95,7 +97,7 @@ bool SingleList::insert(int val, int key)
|
||||
|
||||
/** remove
|
||||
* @brief Removes a value in the list by calling a private member and handling output
|
||||
*
|
||||
*
|
||||
* @param val Value to be removed from the list
|
||||
* @return true If the value was removed from the list
|
||||
* @return false If the value was not removed from the list
|
||||
@@ -103,7 +105,7 @@ bool SingleList::insert(int val, int key)
|
||||
bool SingleList::remove(int val)
|
||||
{
|
||||
bool removed = remove(val, head);
|
||||
if (removed)
|
||||
if (removed)
|
||||
std::cout << "[" << val << "] was removed from the list\n";
|
||||
else std::cout << "[" << val << "] could not be removed from the list\n";
|
||||
return removed;
|
||||
@@ -111,7 +113,7 @@ bool SingleList::remove(int val)
|
||||
|
||||
/** replace
|
||||
* @brief Replaces a value in the list by calling a private member and handling output
|
||||
*
|
||||
*
|
||||
* @param val Value to insert into the list
|
||||
* @param key Value to be replaced within the list
|
||||
* @return true If the key has been replaced in the list by val
|
||||
@@ -120,7 +122,7 @@ bool SingleList::remove(int val)
|
||||
bool SingleList::replace(int val, int key)
|
||||
{
|
||||
bool replaced = replace(val, key, head);
|
||||
if (replaced)
|
||||
if (replaced)
|
||||
std::cout << "[" << key << "] was replaced by [" << val << "] in the list\n";
|
||||
else std::cout << "[" << key << "] could not be replaced by [" << val << "] in the list\n";
|
||||
return replaced;
|
||||
@@ -147,7 +149,7 @@ void SingleList::makeEmpty()
|
||||
|
||||
/** isEmpty
|
||||
* @brief Determine if the SingleList is empty
|
||||
*
|
||||
*
|
||||
* @return true If the SingleList::head is NULL
|
||||
* @return false If the SingleList::head contains data
|
||||
*/
|
||||
@@ -158,14 +160,15 @@ bool SingleList::isEmpty() const
|
||||
|
||||
/** peek
|
||||
* @brief returns the value at the SingleList::head
|
||||
*
|
||||
*
|
||||
* @return int The value held at the Node pointed to by SingleList::head
|
||||
*/
|
||||
void SingleList::peek() const
|
||||
int SingleList::peek() const
|
||||
{
|
||||
if (!isEmpty())
|
||||
if (!isEmpty())
|
||||
std::cout << "[" << head->data << "] is at the top of our list\n";
|
||||
else std::cout << "Nothing to peek, our list is empty...\n";
|
||||
return head->data;
|
||||
}
|
||||
|
||||
/** print
|
||||
@@ -180,7 +183,7 @@ void SingleList::print() const
|
||||
|
||||
/** find
|
||||
* @brief Calls to the private member find() and handles return cases
|
||||
*
|
||||
*
|
||||
* @param val The value to search for within our SingleList
|
||||
* @return true If the value was found in this SingleList
|
||||
* @return false If the value was not found in this SingleList
|
||||
@@ -192,18 +195,19 @@ bool SingleList::find(int val) const
|
||||
std::cout << "[" << val << "] Was not found in our list\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "[" << result->data << "] Was found in our list\n";
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Private Member Functions
|
||||
*****************************************************************************/
|
||||
*****************************************************************************/
|
||||
|
||||
/** insert
|
||||
* @brief Private member to handle inserting value into the list
|
||||
*
|
||||
*
|
||||
* @param val Value to be inserted
|
||||
* @param head The head of the list to insert the value into
|
||||
* @return true If the value was inserted
|
||||
@@ -215,13 +219,13 @@ bool SingleList::insert(int val, Node *&head)
|
||||
// If the list is not empty, update next pointer to head node
|
||||
if (!isEmpty()) newNode->next = head;
|
||||
// Always set head to our newNode
|
||||
head = newNode;
|
||||
head = newNode;
|
||||
return true;
|
||||
}
|
||||
|
||||
/** insert at
|
||||
* @brief Private member to handle inserting a value at a key within our list
|
||||
*
|
||||
*
|
||||
* @param val Value to be inserted
|
||||
* @param key Key value to search for within the list
|
||||
* @param head Head node of the list to insert to
|
||||
@@ -247,7 +251,7 @@ bool SingleList::insert(int val, int key, Node *&head)
|
||||
|
||||
/** remove
|
||||
* @brief Private member to remove values from the list
|
||||
*
|
||||
*
|
||||
* @param val Value to be removed
|
||||
* @param head Head of the list to remove the value from
|
||||
* @return true If the value has been removed from the list
|
||||
@@ -272,7 +276,7 @@ bool SingleList::remove(int val, Node *&head)
|
||||
|
||||
/** replace
|
||||
* @brief Private member to replace values within the list
|
||||
*
|
||||
*
|
||||
* @param val Value to insert into the list
|
||||
* @param key Value to be replaced within the list
|
||||
* @param head Head of the list to replace the value
|
||||
@@ -289,7 +293,7 @@ bool SingleList::replace(int val, int key, Node *&head)
|
||||
|
||||
/** find
|
||||
* @brief Find and return a Node which contains the given value
|
||||
*
|
||||
*
|
||||
* @param val The value to search for within our SingleList
|
||||
* @return SingleList::Node* A pointer to the Node containing the search value
|
||||
*/
|
||||
@@ -310,7 +314,7 @@ SingleList::Node* SingleList::find(int val, Node *start) const
|
||||
|
||||
/** findPrevious
|
||||
* @brief Find and return the Node before a given value
|
||||
*
|
||||
*
|
||||
* @param val The value to search for within our SingleList
|
||||
* @return SingleList::Node* A pointer to the Node previous to the given value
|
||||
*/
|
||||
@@ -330,7 +334,7 @@ SingleList::Node* SingleList::findPrevious(int val, Node *start) const
|
||||
|
||||
/** print
|
||||
* @brief Output the contents of a SingleList from the given Node to NULL
|
||||
*
|
||||
*
|
||||
* @param start The Node to begin traversing output from
|
||||
*/
|
||||
void SingleList::print(Node *start) const
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
## singlelist.h
|
||||
*/
|
||||
|
||||
#ifndef LINKEDLIST_H
|
||||
#define LINKEDLIST_H
|
||||
#ifndef SINGLELIST_H
|
||||
#define SINGLELIST_H
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@@ -30,7 +30,7 @@ class SingleList{
|
||||
bool replace(int val, int key);
|
||||
void makeEmpty();
|
||||
bool isEmpty() const;
|
||||
void peek() const;
|
||||
int peek() const;
|
||||
void print() const;
|
||||
bool find(int val) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user