#include "Node.h" #include #include using std::to_string; using std::string; using std::stringstream;
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am
#include "Node.h" #include #include using std::to_string; using std::string; using std::stringstream;
#include <string>
#include <sstream>
using std::to_string;
using std::string;
using std::stringstream;
template<class T>
class UnorderedList {
private:
Node<T>* head;
Node<T>* tail;
int size;
public:
UnorderedList()
{
head = tail =nullptr;
size = 0;
}
~UnorderedList()
{
clear_list();
}
//Note: Including const at the end ofthe function
//makes this method safe to call from aconst declared
//object. For example:
// constUnorderedList<string> my_list;
//
//can call any method with "const" atthe end.
//i.e., "my_list.get_size()"
//but CANNOT call"my_list.append("blah")", for example.
//This is used to define operator= foryour PigLatinWord
//class to make it more compatable withother STLs/classes.
//Additionally, do NOT put "const" onany mutator methods,
//as all mutator methods result in achange in the object,
//which goes against the idea ofconstants.
int getSize() const
{
return size;
}
//This method is already complete foryou.
//Adds a new node to the beginning ofthe
//linked list.
void prepend(const T& new_data)
{
//Create the newnode and make head point to it.
Node<T>*temp = new Node<T>(new_data, head);
head = temp;
//If head isempty, then also set tail to point to it.
if (head ==nullptr)
tail= temp;
size++;
}
//This method is already complete foryou.
//Adds a new node to the end of thelinked
//list.
void append(const T& new_data)
{
/*Complete theinsert function here */
}
//Inserts a new node at a specificposition
//in the linked list.
bool insert(const T& new_data, intposition)
{
/*Complete theinsert function here */
}
//Removes all nodes from the linkedlist.
//Note: Make sure that all pointers
//are set to null and the size isset
//to zero.
void clearList()
{
/*Complete theclear list function here*/
}
//This method is already complete foryou.
//Removes a node from the front of thelist.
bool popFront(T& data)
{
/*Complete thepopFront function here */
}
//This method is already complete foryou.
//Removes a node from the back of thelist.
bool popBack(T& data)
{
if (tail ==nullptr)
returnfalse;
else
{
Node<T>*temp = head;
Node<T>*temp2 = tail;
while(temp->getNext() != tail)
temp= temp->getNext();
data= tail->getData();
temp->setNext(nullptr);
deletetail;
size--;
returntrue;
}
}
//Removes a node at a specific positionin the Linked List.
bool remove(T& data, intposition)
{
/* Complete theremove function here. */
}
bool getHead(T& data) const
{
if (head !=nullptr)
{
data= head->getData();
returntrue;
}
else
{
returnfalse;
}
}
bool getTail(T& data) const
{
/*Complete thegetTail function here */
}
bool getAt(T& data, int pos)const
{
/*Complete thegetAt function here */
}
string toString(string sep = "")const
{
stringstreamret_str;
for(Node<T>* temp = head; temp != nullptr; temp =temp->getNext())
{
ret_str<< temp->getData() << sep;
}
returnret_str.str();
}
};
How do I get the Node.h header file and what will that looklike
code please to be the answer and do I need another cpp file withthis
this code has already been fixed