Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/salma-mamdoh/rsvector

Our Project for Object Oriented Programming Course taken during Winter 2022 semester
https://github.com/salma-mamdoh/rsvector

backtracking-algorithm cpp data-structures exception-handling filesystem oop problem-solving recursion

Last synced: about 1 month ago
JSON representation

Our Project for Object Oriented Programming Course taken during Winter 2022 semester

Awesome Lists containing this project

README

        

RSVector Class

Introduction

Welcome to the RSVector Class repository! This repository contains the implementation of the RSVector class, which is a dynamic array template class with additional functionality compared to the standard std::vector class. In addition to the RSVector class, this repository also includes implementations of other popular data structures such as set, map, and stack.

The implementations of these data structures use object-oriented programming (OOP) concepts such as exceptions and templates. The functionalities for these data structures include push, pop, insert, and erase.

Furthermore, this repository includes some problem-solving examples on the topic of backtracking, which is a widely used algorithmic technique for solving problems by trying out all possible paths and finding the one that satisfies the given constraints.

Private Members

  • data: A pointer to the dynamically allocated array that stores the elements of the vector.
  • size: The number of elements currently in the vector.
  • capacity: The total capacity of the allocated array.

Public Members

Constructors and Big 4

  • RSVector(int): Initializes the vector with a specific capacity. No content is added, and the size is 0.
  • RSVector(T*, int): Initializes the vector with n items from an array.
  • RSVector(const RSVector&): Initializes the vector with a copy of another vector.
  • ~RSVector(): Deletes the allocated memory.
  • RSVector& operator=(const RSVector&): Copy assignment.
  • RSVector& operator=(RSVector&&): Move assignment.

Access Operations

  • T& operator[](int): Accesses an item by reference. Throws an exception if out of range.

Modifying Operations

  • int push_back(T): Adds an item to the end of the vector and returns the number of items. Increases capacity if needed.
  • T pop_back(): Removes and returns the last element in the vector.
  • void erase(iterator): Removes an item at an iterator. Throws an exception if invalid iterator.
  • void erase(iterator1, iterator2): Removes items between iterator1 and iterator2. Throws an exception if any iterator is outside the range.
  • void clear(): Deletes all vector content.
  • void insert(iterator, T): Inserts an item at an iterator. Throws an exception if invalid iterator.

Iterators

  • iterator begin(): Returns an iterator to the beginning of the vector.
  • iterator end(): Returns an iterator to the end of the vector.

Comparison Operations

  • bool operator==(const RSVector&): Returns true if the vectors are equal.
  • bool operator<(const RSVector&): Compares item by item and returns true if the first different item in this is less than in the other.

Capacity Operations

  • int size() const: Returns the current size of the vector.
  • int capacity() const: Returns the size of the currently allocated array.
  • int resize(): Relocates to a bigger space.
  • bool empty(): Returns true if the size is 0.

Friends

  • friend ostream& operator<<(ostream& out, RSVector): Overloads the << operator to print the vector.

Testing

Multiple client programs should be written to test the class templates on different types. The tests should cover all member functions and edge cases, such as adding and removing elements, resizing, and copying. This will ensure that the implementations are correct and robust.

Conclusion

The RSVector Class repository is intended for anyone who wants to learn more about OOP, data structures, and problem-solving. Whether you're a beginner or an experienced programmer, you'll find useful information and examples in this repository. We encourage you to explore the code and solutions, and to experiment with the data structures and algorithms to deepen your understanding and improve your skills.