TheAlgorithms / C-Plus-Plus

Collection of various algorithms in mathematics, machine learning, computer science and physics implemented in C++ for educational purposes.
https://thealgorithms.github.io/C-Plus-Plus
MIT License
29.71k stars 7.05k forks source link

Create linkedlist_using_class.cpp #2667

Closed yash2154 closed 6 months ago

yash2154 commented 7 months ago

This C++ code defines a simple linked list and provides various operations on it through a LinkedList. This implementation leverages object-oriented programming principles, utilizing a class-based approach to manage the linked list. The object-oriented paradigm enhances code organization and encapsulation compared to a functional programming approach, offering improved modularity and ease of maintenance.

Node Structure: Defines a basic structure Node with an integer data and a pointer next to the next node.

LinkedList Class: Manages a linked list with a head and tail pointer. Provides methods for inserting a node at the end (InsertAtEnd), at the beginning (InsertAtBeginning), displaying the list (Display), reversing the list (reverse), removing a specific value (Remove), and removing a node at a given index (RemoveNth). Overloads the + operator to concatenate two linked lists.

Noteable Functions:

reverse: Reverses the linked list in-place. operator+: Concatenates two linked lists. kgroup: Performs a k-group reversal on the linked list. Memory Management: The code uses dynamic memory allocation (new and delete) for creating and deleting nodes.

Usage: The main function serves as a trial run, demonstrating the usage of various methods and operations provided by the LinkedList class. Additionally, a testcase function has been added to showcase specific scenarios, including the insertion of elements, list reversal, concatenation, k-group reversal, and removal of elements. This testcase function provides a practical example of how to utilize the linked list functionalities in a more structured manner.

github-actions[bot] commented 6 months ago

This pull request has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] commented 6 months ago

Please ping one of the maintainers once you commit the changes requested or make improvements on the code. If this is not the case and you need some help, feel free to ask for help in our Gitter channel or our Discord server. Thank you for your contributions!