#include <iostream>
#include <stdlib.h>
struct customer {
void random_customer() {}
};
class Node
{
private:
customer data;
Node *next;
public:
/*Nodes constructors*/
Node(){next=nullptr;}
Node(customer X)
{
data=X;
next=nullptr;
}
/*Data setters and getters*/
void set_Data(customer X)
{data = X;}
customer get_Data()
{return data;}
/*next setters and getters*/
void set_next(Node * X){next=X;}
Node* get_next(){return next;}
};
class List
{
private:
Node * head;
Node * tail;
int counter;
public:
/*Constructors*/
List(){head=nullptr;tail=head;counter=0;}
/*Copy constructor*/
List(const List& rhs) { *this = rhs; }
/*copy operator*/
List& operator=(const List& rhs)
{
Clear();
Node* temp = rhs.head;
while (temp) {
add_End(temp->get_Data());
temp = temp->get_next();
}
return *this;
}
/*Checks if the list is empty*/
bool isEmpty()
{
if (head==nullptr)
return true;
return false;
}
/*front manipulation*/
void add_Front(customer item)
{
if (isEmpty())
{
head = new Node(item);
tail = head;
counter++;
}
else{
Node * nw= new Node(item);
nw ->set_next(head);
head=nw;
counter++;
}
}
void pop_Front()
{
if (isEmpty())
return;
if (head==tail)
{
delete head;
head = tail = nullptr;
counter--;
return;
}
Node * temphead=head;
head=head->get_next();
delete temphead;
counter--;
}
/*End Manipulation*/
void add_End(customer X)
{
if(isEmpty()){
add_Front(X);
counter++;}
else
{
Node * temp=new Node(X);
tail->set_next(temp);
tail=temp;
counter++;
}
}
/*freeing the whole list*/
void Clear()
{
while (!isEmpty())
pop_Front();
}
/*Destructor*/
~List(){Clear();}
/*Extras*/
int get_Size(){return counter;}
customer get_Front(){return head->get_Data();}
customer get_End(){return tail->get_Data();}
};
using namespace std;
int main()
{
List Data;
int numberofelements;
cout<<"How many customers you wanna randomly generate? : ";
cin >> numberofelements;
srand(time(NULL));
for (int i=0; i<numberofelements; i++)
{
customer temp;
temp.random_customer();
Data.add_Front(temp);
}
{
List Data2;
Data2 = Data;
}
List Data3 { Data };
std::cout << "here goes the destructor\n";
return 0;
}