DSlib is a lightweight and efficient C++ library that provides implementations for common data structures such as:
- Stack
- Queue
- Binary Search Tree (BST)
- Linked List
This library is designed to help developers easily integrate these data structures into their projects.
- Stack: Push, pop, peek operations.
- Queue: Enqueue, dequeue, peek operations.
- Binary Search Tree (BST): Insert, search, delete, and traversal operations.
- Linked List: Insert, delete, search, and traversal operations.
To use DSlib, ensure you have:
- A C++ compiler (e.g.,
g++,clang++). - Git installed (optional, for cloning the repository).
-
Clone the repository:
git clone https://github.com/OsamaBendary/DSlib.git cd DSlib -
Build the static library:
g++ -c DS.cpp -o DS.o ar rcs libds.a DS.o
This will create a static library file named
libds.ain the project directory.
-
Include the header file in your project:
#include "DS.h"
-
Compile your project while linking the library. Here's an example:
g++ main.cpp -o main -L. -lds
main.cppis your C++ source file.-L.tells the compiler to look for libraries in the current directory.-ldslinks thelibds.alibrary.
-
Run the compiled program:
./main
Below is an example of how to use DSlib in your project:
#include<iostream>
#include"DS.cpp"
using namespace std;
int main(){
linkedlist l1;
l1.insertatbeginning("1");
l1.insertatbeginning("2");
l1.insertatbeginning("3");
l1.insertatbeginning("4");
l1.insertatbeginning("5");
l1.insertatend("6");
l1.insertatposition("0",2);
l1.deleteatposition(2);
l1.deleteatposition(1);
l1.display();
l1.reverse();
l1.display();
l1.search("3");
l1.search("10");
l1.deletelast();
l1.display();
stack s1;
s1.push("1");
s1.push("2");
s1.push("3");
s1.pop();
s1.display();
queue q1;
q1.enqueue("1");
q1.enqueue("2");
q1.enqueue("3");
q1.dequeue();
q1.display();
tree t1;
t1.insert("5");
t1.insert("3");
t1.insert("7");
t1.insert("2");
t1.insert("4");
t1.insert("6");
t1.insert("8");
t1.search("3");
t1.display();
return 0;
}Compile and run the example:
g++ main.cpp -o main -L. -lds
./mainTo clean up the generated files, run:
rm -f *.o *.a mainContributions are welcome! Feel free to open issues or submit pull requests for bug fixes, feature requests, or improvements.
This project is licensed under the MIT License - see the LICENSE file for details.
Happy coding!