Anda di halaman 1dari 3

#include <iostream>

#include <cstring>
using namespace std;

struct Persons
{
string firstName;
string secondName;
string CNP;
string Email;
};

class NODE
{
private:
NODE *next;
public:
Persons *box = new Persons();
NODE(string firstName, string secondName, string CNP, string Email)
{
box->firstName = firstName;
box->secondName = secondName;
box->CNP = CNP;
box->Email = Email;
}
void SetNext(NODE *next)
{
this->next = next;
}
NODE* GetNext()
{
return next;
}
};

class QueueSinglyLinkedList
{
private:
NODE *front;
NODE *rear;
public:
QueueSinglyLinkedList()
{
front = NULL;
rear = NULL;
}
bool isEmpty()
{
return front == NULL;
}
void InsertNODE(NODE *newNode)
{
if (isEmpty())
front = rear = newNode;
else
rear->SetNext(newNode);
rear = newNode;
rear->SetNext(NULL);
}
void DeleteNODE()
{
if (isEmpty())
cout << "\n Queue is Empty." << endl;
else
{
NODE *temp = front;
front = front->GetNext();
delete temp;
}
}
void Print()
{
if (isEmpty())
cout << "\n Queue is Empty.";
else
{
NODE *temp = front;
while (temp->GetNext() != NULL)
{
cout << "\n First Name : " << temp->box->firstName;
cout << "\n Second Name : " << temp->box->secondName;
cout << "\n CNP : " << temp->box->CNP;
cout << "\n Email : " << temp->box->Email;
temp = temp->GetNext();
cout << endl;
}
cout << "\n First Name : " << temp->box->firstName;
cout << "\n Second Name : " << temp->box->secondName;
cout << "\n CNP : " << temp->box->CNP;
cout << "\n Email : " << temp->box->Email;
}
cout << endl;
}
};

int main()
{
QueueSinglyLinkedList *ptr = new QueueSinglyLinkedList();

NODE obj1(NODE("Dragu", "Stelian", "1911226284570",


"dragu_stelian@yahoo.com"));
NODE obj2(NODE("Dragu", "Mircea", "1891226284462",
"mircead.personal@yahoo.com"));
NODE obj3(NODE("David", "Adrian", "1971226284462",
"david_adrian@yahoo.com"));
NODE obj4(NODE("Afrem", "Dragos", "1981246627446",
"afrem_dragos@yahoo.com"));
NODE obj5(NODE("Sandu", "Marius", "1984225774462",
"sandu.marius@yahoo.com"));

ptr->InsertNODE(&obj1);
ptr->InsertNODE(&obj2);
ptr->InsertNODE(&obj3);
ptr->InsertNODE(&obj4);
ptr->InsertNODE(&obj5);

ptr->Print();

ptr->DeleteNODE();
ptr->DeleteNODE();
ptr->DeleteNODE();
ptr->DeleteNODE();
ptr->DeleteNODE();
ptr->DeleteNODE();

ptr->Print();
return 0;
}

Anda mungkin juga menyukai