This repository contains a simple implementation of a linked list template in C++. It demonstrates how to define and implement a template class in C++ for creating and managing a singly linked list. The project is structured into a header file, a template implementation file, and a main driver program.
linked_list_template.h
: Header file containing the template class declaration for the linked list.linked_list_template.tpp
: Implementation file for the template class. This includes the definitions of the member functions declared in the header file.main.cpp
: Main driver program that demonstrates the usage of thelist
template class with different operations.Makefile
: A simple Makefile to compile the project using g++ and generate an executable.
The list
template class supports the following operations:
- Default construction, copy construction, move construction.
- Copy assignment and move assignment.
- Appending elements to the end of the list.
- Adding another list to the end of the current list.
- Accessing elements by index.
- Getting the size of the list.
- Printing the list elements to the standard output.
Ensure you have a C++ compiler that supports C++17 (or later) installed. This project was tested with the GNU compiler.
To compile the project, simply run:
make
This will generate an executable named linked_list
. You can run this executable to see the list
class in action:
./linked_list
To clean up the compiled files, you can use:
make clean
The main.cpp
file demonstrates how to use the list
class with int
type, including operations like appending elements, accessing elements by index, and utilizing the copy/move constructors and assignment operators. It also shows how to add one list to another and print the contents of a list.
Feel free to fork this repository and submit pull requests to contribute to this project. Whether it's adding new features, fixing bugs, or improving documentation, all contributions are welcome!