0% found this document useful (0 votes)
15 views1 page

CplusplusLinkedList CPP

The document defines a class EduLinkedList for managing a linked list of EduLinkedListNode objects. It includes methods for inserting nodes at the head, creating a linked list from an integer array, and converting the list to a string representation. The class initializes with a head pointer and provides functionality to manipulate the linked list structure.

Uploaded by

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

CplusplusLinkedList CPP

The document defines a class EduLinkedList for managing a linked list of EduLinkedListNode objects. It includes methods for inserting nodes at the head, creating a linked list from an integer array, and converting the list to a string representation. The class initializes with a head pointer and provides functionality to manipulate the linked list structure.

Uploaded by

xyza04481
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include "LinkedListNode.

cpp"

// Template for the linked list


class EduLinkedList
{
public:
EduLinkedListNode *head = new EduLinkedListNode(0);
// EduLinkedList() will be used to make a EduLinkedList type object
EduLinkedList() { head = nullptr; }
EduLinkedList(EduLinkedListNode *h) { head = h; }
// InsertNodeAtHead() method will insert a LinkedListNode at head
// of a linked list.
void InsertNodeAtHead(EduLinkedListNode *node)
{
if (head != nullptr)
{
node->next = head;
head = node;
}
else
{
head = node;
}
}
// CreateLinkedList() method will create the linked list using the
// given integer array with the help of InsertAthead method.
void CreateLinkedList(std::vector<int> &vec)
{
for (int i = vec.size() - 1; i >= 0; i--)
{
EduLinkedListNode *node = new EduLinkedListNode(vec[i]);
InsertNodeAtHead(node);
}
}
// ToString() method will display the elements of linked list.
std::string ToString()
{
std::string result = "[";
EduLinkedListNode *temp = head;
while (temp != nullptr)
{
result += std::to_string(temp->data);
temp = temp->next;
if (temp != nullptr)
{
result += ",";
}
}
result += "]";
return result;
}
};

You might also like