0% found this document useful (0 votes)
91 views3 pages

Queue Singly Linked List

The document defines a QueueSinglyLinkedList data structure for storing Person objects in a linked list. It contains NODE and Persons structs to store data, and methods for the queue like InsertNODE to add nodes, DeleteNODE to remove nodes, and Print to output the queued data. The main function demonstrates adding 5 Person nodes to the queue, deleting them, and printing the empty queue.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
91 views3 pages

Queue Singly Linked List

The document defines a QueueSinglyLinkedList data structure for storing Person objects in a linked list. It contains NODE and Persons structs to store data, and methods for the queue like InsertNODE to add nodes, DeleteNODE to remove nodes, and Print to output the queued data. The main function demonstrates adding 5 Person nodes to the queue, deleting them, and printing the empty queue.

Uploaded by

Dragu Stelian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 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;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy