2020-05-07 20:21:14 +00:00
|
|
|
/*#############################################################################
|
|
|
|
## Author: Shaun Reed ##
|
|
|
|
## Legal: All Content (c) 2020 Shaun Reed, all rights reserved ##
|
2020-05-07 20:23:01 +00:00
|
|
|
## About: An example of a circular doubly linked list ##
|
2020-05-07 20:21:14 +00:00
|
|
|
## ##
|
|
|
|
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
|
|
|
##############################################################################
|
2020-05-07 20:23:01 +00:00
|
|
|
## circledoublelist.cpp
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "circledoublelist.h"
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Constructors, Destructors, Operators
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/** copy constructor
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Construct a new CircleDoubleList::CircleDoubleList object from an existing one
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param rhs CircleDoubleList object
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
CircleDoubleList::CircleDoubleList(const CircleDoubleList& rhs)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
Node *cp = rhs.tail;
|
2020-05-07 20:21:14 +00:00
|
|
|
Node *tempHead;
|
2020-05-07 20:23:01 +00:00
|
|
|
if (cp == NULL) tail = NULL;
|
2020-05-07 20:21:14 +00:00
|
|
|
else {
|
2020-05-07 20:23:01 +00:00
|
|
|
tail = new Node(cp->data);
|
|
|
|
tempHead = tail;
|
2020-05-07 20:21:14 +00:00
|
|
|
while (cp->next != NULL) {
|
|
|
|
cp = cp->next;
|
2020-05-07 20:23:01 +00:00
|
|
|
tail->next = new Node(cp->data);
|
|
|
|
tail = tail->next;
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
2020-05-07 20:23:01 +00:00
|
|
|
tail = tempHead;
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
2020-05-07 20:23:01 +00:00
|
|
|
|
2020-05-07 20:21:14 +00:00
|
|
|
/** operator=
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Assign two CircleDoubleList objects equal using copy constr and class destr
|
2020-05-07 20:21:14 +00:00
|
|
|
* Pass the rhs by value to create local copy, swap its contents
|
2020-05-07 20:23:01 +00:00
|
|
|
* Destructor called on previous CircleDoubleList data at the end of this scope
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param rhs CircleDoubleList object passed by value
|
|
|
|
* @return CircleDoubleList A deep copy of the rhs CircleDoubleList object
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
CircleDoubleList CircleDoubleList::operator=(CircleDoubleList rhs)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
if (this != &rhs) return *this;
|
2020-05-07 20:23:01 +00:00
|
|
|
std::swap(tail, rhs.tail);
|
2020-05-07 20:21:14 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** destructor
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Destroy the CircleDoubleList::CircleDoubleList object
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
CircleDoubleList::~CircleDoubleList()
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
makeEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Public Member Functions
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
/** insert
|
|
|
|
* @brief Inserts a value to the head of our linked list
|
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param val The value to be inserted
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::insert(int val)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
bool inserted = insert(val, tail);
|
2020-05-07 20:21:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::insert(int val, int key)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
// Check that we are not trying to insert at a position within an empty list
|
|
|
|
if (tail == NULL) {
|
|
|
|
std::cout << "Cannot insert at a key value using an empty list\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool inserted = insert(val, key, tail->next);
|
2020-05-07 20:21:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** remove
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Removes a value in the list by calling overloaded private member and handling output
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::remove(int val)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
// Check that we are not trying to remove from an empty list
|
|
|
|
if (isEmpty()) {
|
|
|
|
std::cout << "Cannot remove from an empty list\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to remove the item
|
|
|
|
bool removed = remove(val, tail->next);
|
2020-05-07 20:21:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** replace
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Replaces a value in the list by calling overloaded private member and handling output
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
|
|
|
* @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
|
|
|
|
* @return false If the key has not been replaced in the list by val
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::replace(int val, int key)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
// Check that we are not trying to replace within an empty list
|
|
|
|
if (isEmpty()) {
|
|
|
|
std::cout << "Cannot replace anything within an empty list\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to replace the item
|
|
|
|
bool replaced = replace(val, key, tail->next);
|
2020-05-07 20:21:14 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** makeEmpty
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Empty this CircleDoubleList object, deleting all associated Nodes
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
void CircleDoubleList::makeEmpty()
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
Node *nextNode;
|
|
|
|
if (isEmpty()) return;
|
|
|
|
|
|
|
|
// Start deletion from the head of the list
|
|
|
|
nextNode = tail->next;
|
|
|
|
while(!isEmpty()) {
|
2020-05-07 20:21:14 +00:00
|
|
|
nextNode = nextNode->next;
|
2020-05-07 20:23:01 +00:00
|
|
|
remove(nextNode->prev->data);
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
2020-05-07 20:23:01 +00:00
|
|
|
nextNode = NULL;
|
|
|
|
return;
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** isEmpty
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Determine if the CircleDoubleList is empty
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @return true If the CircleDoubleList::tail is NULL
|
|
|
|
* @return false If the CircleDoubleList::tail contains data
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::isEmpty() const
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
return tail == NULL;
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** peek
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief returns the value at the CircleDoubleList::head
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @return int The value held at the Node pointed to by CircleDoubleList::head
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
int CircleDoubleList::peek() const
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
if (!isEmpty())
|
2020-05-07 20:23:01 +00:00
|
|
|
std::cout << "[" << tail->next->data << "] is at the top of our list\n";
|
2020-05-07 20:21:14 +00:00
|
|
|
else std::cout << "Nothing to peek, our list is empty...\n";
|
2020-06-04 12:48:45 +00:00
|
|
|
// If the list has data we return it, otherwise we return the smallest possible int (error)
|
|
|
|
return (!isEmpty()) ? tail->data : INT32_MIN;
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** print
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Output the data held by the CircleDoubleList object
|
2020-05-07 20:21:14 +00:00
|
|
|
* Calls to the private print()
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
void CircleDoubleList::print() const
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
// Print from the head of our list
|
|
|
|
if(!isEmpty()) print(tail->next);
|
2020-05-07 20:21:14 +00:00
|
|
|
else std::cout << "Nothing to print, our list is empty...\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
/** find
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Calls to overloaded private member find() and handles output
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param val The value to search for within our CircleDoubleList
|
|
|
|
* @return true If the value was found in this CircleDoubleList
|
|
|
|
* @return false If the value was not found in this CircleDoubleList
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::find(int val) const
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
// Check that we are not trying to search an empty list
|
|
|
|
if (isEmpty()) {
|
|
|
|
std::cout << "Cannot search an empty list\n";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Node *result = find(val, tail);
|
2020-05-07 20:21:14 +00:00
|
|
|
if( result == NULL) {
|
|
|
|
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
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param tail The tail node of the list to insert the value into
|
2020-05-07 20:21:14 +00:00
|
|
|
* @return true If the value was inserted
|
|
|
|
* @return false If the value could not be inserted
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::insert(int val, Node *&tail)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
Node *newNode = new Node(val);
|
|
|
|
if (!isEmpty()) {
|
2020-05-07 20:23:01 +00:00
|
|
|
// Relink the current head to the node after newNode
|
|
|
|
newNode->next = tail->next;
|
|
|
|
tail->next->prev = newNode;
|
2020-07-12 00:55:15 +00:00
|
|
|
// Relink our head and tail nodes, making newNode the head node
|
2020-05-07 20:23:01 +00:00
|
|
|
tail->next = newNode;
|
|
|
|
newNode->prev = tail;
|
2020-05-07 20:21:14 +00:00
|
|
|
}
|
2020-05-07 20:23:01 +00:00
|
|
|
else tail = newNode;
|
2020-05-07 20:21:14 +00:00
|
|
|
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
|
|
|
|
* @return true If the value was inserted
|
|
|
|
* @return false If the value was not inserted
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::insert(int val, int key, Node *&head)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
Node *newNode = new Node(val);
|
|
|
|
// Let insert() handle inserting at the head
|
2020-05-07 20:23:01 +00:00
|
|
|
if (head->data == key) return insert(val);
|
2020-05-07 20:21:14 +00:00
|
|
|
|
2020-05-07 20:23:01 +00:00
|
|
|
// Get the node which contains our value
|
2020-05-07 20:21:14 +00:00
|
|
|
Node *keyNode = find(key, head);
|
2020-05-07 20:23:01 +00:00
|
|
|
// If there was no keyNode found, the key is not in our list, do nothing
|
2020-05-07 20:21:14 +00:00
|
|
|
if (keyNode == NULL) return false;
|
2020-05-07 20:23:01 +00:00
|
|
|
// Insert the newNode in front of the previous to the keyNode
|
|
|
|
// [head]->[key]->[tail]
|
|
|
|
// [head]->[new]->[key]->[tail]
|
2020-05-07 20:21:14 +00:00
|
|
|
newNode->prev = keyNode->prev;
|
|
|
|
keyNode->prev->next = newNode;
|
|
|
|
|
|
|
|
// Change the keyNode->prev ptr to newNode
|
|
|
|
newNode->next = keyNode;
|
|
|
|
keyNode->prev = newNode;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
|
|
|
* @return false If the value has not been removed from the list
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::remove(int val, Node *&head)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
2020-05-07 20:23:01 +00:00
|
|
|
// If there is only one node in the list
|
|
|
|
// Synonymous with: if (tail = tail->next)
|
|
|
|
if (head == head->next) {
|
|
|
|
delete tail;
|
|
|
|
tail = NULL;
|
|
|
|
// Nothing to relink, list is empty
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the head node contains the value to remove
|
|
|
|
if (head->data == val) {
|
|
|
|
Node *temp = head;
|
|
|
|
// Move head to the next node in the list
|
2020-05-07 20:21:14 +00:00
|
|
|
head = head->next;
|
2020-05-07 20:23:01 +00:00
|
|
|
// Relink head and tail nodes
|
|
|
|
head->prev = tail;
|
|
|
|
tail->next = head;
|
|
|
|
// Delete dangling pointer created by relinking
|
|
|
|
delete temp;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the tail node contains the value to remove
|
|
|
|
if (tail->data == val) {
|
|
|
|
Node *temp = tail;
|
|
|
|
// Move tail to the previous node in the list
|
|
|
|
tail = tail->prev;
|
|
|
|
// Relink head and tail nodes
|
|
|
|
head->prev = tail;
|
|
|
|
tail->next = head;
|
|
|
|
// Delete dangling pointer created by relinking
|
|
|
|
delete temp;
|
2020-05-07 20:21:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-05-07 20:23:01 +00:00
|
|
|
// Search for the value further within our list
|
2020-05-07 20:21:14 +00:00
|
|
|
Node *keyNode = find(val, head);
|
2020-05-07 20:23:01 +00:00
|
|
|
// If NULL, the value does not exist within our list
|
2020-05-07 20:21:14 +00:00
|
|
|
if (keyNode == NULL) return false;
|
2020-05-07 20:23:01 +00:00
|
|
|
// Relink surrounding nodes to make keyNode a dangling ptr
|
|
|
|
keyNode->next->prev = keyNode->prev;
|
|
|
|
keyNode->prev->next = keyNode->next;
|
|
|
|
// Delete the dangling node created by relinking above
|
|
|
|
delete keyNode;
|
|
|
|
keyNode = NULL;
|
2020-05-07 20:21:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** 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
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param head Head node of the list to modify
|
2020-05-07 20:21:14 +00:00
|
|
|
* @return true If the key has been replaced by val within the list
|
|
|
|
* @return false If the key has not been replaced by val within the list
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
bool CircleDoubleList::replace(int val, int key, Node *&head)
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
Node *replacee = find(key, head);
|
|
|
|
if (replacee == NULL) return false;
|
|
|
|
replacee->data = val;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** find
|
|
|
|
* @brief Find and return a Node which contains the given value
|
|
|
|
*
|
2020-05-07 20:23:01 +00:00
|
|
|
* @param val The value to search for within our CircleDoubleList
|
|
|
|
* @param start The node to begin the search from, returns on the first found result
|
|
|
|
* @return CircleDoubleList::Node* A pointer to the Node containing the search value
|
2020-05-07 20:21:14 +00:00
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
CircleDoubleList::Node* CircleDoubleList::find(int val, Node *start) const
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
// If given a NULL list, return NULL
|
|
|
|
// If given a head which contains the requested value, return the foundNode
|
|
|
|
if (start == NULL || start->data == val) return start;
|
|
|
|
|
2020-05-07 20:23:01 +00:00
|
|
|
// Copy our start position, check its value
|
2020-05-07 20:21:14 +00:00
|
|
|
Node *foundNode = start;
|
2020-05-07 20:23:01 +00:00
|
|
|
if (foundNode->data == val) return foundNode;
|
|
|
|
// Keep checking the next node until we reach the start value again
|
|
|
|
while (foundNode->next != start) {
|
2020-05-07 20:21:14 +00:00
|
|
|
foundNode = foundNode->next;
|
|
|
|
if (foundNode->data == val) return foundNode;
|
|
|
|
}
|
|
|
|
// If we have not yet returned a foundNode, the key is not in our list
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** print
|
2020-05-07 20:23:01 +00:00
|
|
|
* @brief Output the contents of a CircleDoubleList from the given Node to NULL
|
2020-05-07 20:21:14 +00:00
|
|
|
*
|
|
|
|
* @param start The Node to begin traversing output from
|
|
|
|
*/
|
2020-05-07 20:23:01 +00:00
|
|
|
void CircleDoubleList::print(Node *start) const
|
2020-05-07 20:21:14 +00:00
|
|
|
{
|
|
|
|
Node *temp = start;
|
2020-05-07 20:23:01 +00:00
|
|
|
std::cout << "List Contents: " << temp->data << " | ";
|
|
|
|
temp = temp->next;
|
|
|
|
while (temp != start) {
|
2020-05-07 20:21:14 +00:00
|
|
|
std::cout << temp->data << " | ";
|
|
|
|
temp = temp->next;
|
|
|
|
}
|
|
|
|
std::cout << std::endl;
|
|
|
|
}
|