This repository contains a collection of custom data structures implemented in C++. These data structures can be useful for various programming tasks, and they include:
- Vector: A dynamic array implementation that can resize itself as needed.
- Linked List: A singly linked list implementation.
- Double Linked List: A doubly linked list implementation.
- Circular Linked List: A circular singly linked list implementation.
- Double Circular Linked List: A circular doubly linked list implementation.
- Queue: A basic queue data structure.
- Stack: A basic stack data structure.
- Binary Tree: An implementation of a binary tree.
- Tree: An implementation of a generic tree.
- Graph: An implementation of a graph data structure.
The Vector
class is a dynamic array that can grow in size as elements are added. It includes the following methods:
#include "Vector.h"
int main() {
// Create a vector of integers
Vector<int> myVector;
// Add elements to the vector
myVector.push_back(10);
myVector.push_back(20);
myVector.push_back(30);
// Access elements by index
int element = myVector.at(1); // element = 20
// Get the number of elements and capacity
size_t size = myVector.size(); // size = 3
size_t capacity = myVector.capacity(); // capacity = 4 (initial capacity is 2)
// Remove the last element
myVector.pop_back(); // Vector contains [10, 20] after this operation
// Check if the vector is empty
bool isEmpty = myVector.empty(); // isEmpty = false
// Clear the vector and free memory
myVector.clear();
return 0;
}
The LinkedList
class is a singly linked list with methods for manipulation:
#include "LinkedList.h"
int main() {
// Create a linked list of integers
LinkedList<int> myList;
// Add elements to the linked list
myList.push_back(10);
myList.push_back(20);
myList.push_back(30);
// Access elements by index
int element = myList.at(1); // element = 20
// Get the number of elements
size_t count = myList.count(); // count = 3
// Remove the last element
myList.pop_back(); // Linked list contains [10, 20] after this operation
// Check if the linked list is empty
bool isEmpty = myList.empty(); // isEmpty = false
// Clear the linked list and free memory
myList.clear();
return 0;
}