From 0901821ce7dfb6c2aef8883646e9d8b3a370effc Mon Sep 17 00:00:00 2001 From: nishant4500 <135944619+nishant4500@users.noreply.github.com> Date: Mon, 7 Oct 2024 16:13:02 +0530 Subject: [PATCH 1/9] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2bd673209..e7ec7869d 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ We aim to: - **Multi-language Support**: Algorithms in multiple programming languages - **Beginner-Friendly**: Well-structured, easy-to-understand explanations - **Open Source Contributions**: Welcoming developers at all levels to contribute +- **Community Forum**: A new interactive platform where developers can ask questions, share ideas, and collaborate in real-time. This forum will help bridge the gap between beginners and experts, allowing for deeper engagement and problem-solving. ## Website From 6848b385e2916b82d206805720979d70b28fcf5f Mon Sep 17 00:00:00 2001 From: nishant Date: Tue, 8 Oct 2024 09:57:58 +0530 Subject: [PATCH 2/9] Your commit message --- docs/programming-fundamentals/OperatorOverloading.md | 0 docs/programming-fundamentals/pointers.md | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 docs/programming-fundamentals/OperatorOverloading.md create mode 100644 docs/programming-fundamentals/pointers.md diff --git a/docs/programming-fundamentals/OperatorOverloading.md b/docs/programming-fundamentals/OperatorOverloading.md new file mode 100644 index 000000000..e69de29bb diff --git a/docs/programming-fundamentals/pointers.md b/docs/programming-fundamentals/pointers.md new file mode 100644 index 000000000..e69de29bb From a30cd4ab8725468274b807b18bc6caa1b50a6541 Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:18:42 +0530 Subject: [PATCH 3/9] Update OperatorOverloading.md --- .../OperatorOverloading.md | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/docs/programming-fundamentals/OperatorOverloading.md b/docs/programming-fundamentals/OperatorOverloading.md index e69de29bb..02589e32d 100644 --- a/docs/programming-fundamentals/OperatorOverloading.md +++ b/docs/programming-fundamentals/OperatorOverloading.md @@ -0,0 +1,96 @@ +--- +id: programming-fundamentals +title: Operator Overloading +sidebar_label: Introduction to Operator Overloading +sidebar_position: 2 +description: 'Operator overloading allows you to redefine the way operators work for user-defined types (classes and structs). It enables you to specify more intuitive ways to perform operations on objects of your classes.' +tags: [dsa, data-structures, Operator Overloading] +--- + +## 2 Operator Overloading + +### Introduction + +Operator overloading allows you to redefine the way operators work for user-defined types (classes and structs). It enables you to specify more intuitive ways to perform operations on objects of your classes. + +Overloading an operator does not change: +- the operator precedence, +- the associativity of the operator, +- the arity of the operator, or +- the meaning of how the operator works on objects of +built-in types. + +### Syntax +An overloaded operator is implemented as a special member function with the keyword `operator` followed by the symbol of the operator being overloaded. + +```cpp +class ClassName { +public: + ReturnType operatorOpSymbol (ParameterList) { + // Function body + } +}; +``` +### Example +```cpp +class Complex { +public: + double real, imag; + Complex(double r = 0, double i = 0) : real(r), imag(i) {} + // Overload the + operator + Complex operator+ (Complex& obj) { + return Complex(real + obj.real, imag + obj.imag); + } +}; +``` + +### Types of Operators that Can Be Overloaded + +- Arithmetic operators: `+`, `-`, `*`, `/`, `%` +- Relational operators: `==`, `!=`, `<`, `>`, `<=`, `>=` +- Logical operators: `&&`, `||`, `!` +- Bitwise operators: `&`, `|`, `^`, `~`, `<<`, `>>` +- Increment and decrement operators: `++`, `--` +- Assignment operators: `=`, `+=`, `-=`, `*=`, `/=`, `%=` +- Subscript operator: `[]` +- Function call operator: `()` +- Member access operators: `->`, `.` (only for pointers to members) +- Input and output operators: `>>`, `<<` + +Operators that **cannot** be overloaded include: `::`, `.*`, `.`, `? :`, `sizeof` + +### Example: +```cpp +#include + +class Complex { +public: + double real, imag; + + Complex(double r = 0, double i = 0) : real(r), imag(i) {} + + // Overload the == operator + bool operator== (const Complex& obj) const { + return (real == obj.real && imag == obj.imag); + } +}; + +int main() { + Complex c1(3.0, 4.0), c2(3.0, 4.0); + if (c1 == c2) { + std::cout << "c1 and c2 are equal" << std::endl; + } else { + std::cout << "c1 and c2 are not equal" << std::endl; + } + return 0; +} +``` + +### Operator Overloading Rules + +When overloading operators, there are several rules to keep in mind: + +1. **Preserve the Operator's Original Meaning**: The overloaded operator should make sense in the context of the operation it performs. +2. **Return Types**: The return type should be appropriate for the operation. For example, `operator+` should return a new object, while `operator+=` should return a reference to `*this`. +3. **Symmetry**: Ensure symmetric behavior where applicable. For example, `a == b` should return the same result as `b == a`. +4. **Do Not Overload Operators Irrelevantly**: Only overload operators that make sense for your class. For example, overloading the arithmetic operators for a class that represents a complex number makes sense, but overloading them for a class that represents a database connection does not. From 9d85205b4c8c27799c35a69f9f7414e8739a0bfd Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 10:22:56 +0530 Subject: [PATCH 4/9] Update pointers.md --- docs/programming-fundamentals/pointers.md | 188 ++++++++++++++++++++++ 1 file changed, 188 insertions(+) diff --git a/docs/programming-fundamentals/pointers.md b/docs/programming-fundamentals/pointers.md index e69de29bb..c0d99b508 100644 --- a/docs/programming-fundamentals/pointers.md +++ b/docs/programming-fundamentals/pointers.md @@ -0,0 +1,188 @@ +## 1. What are References and Pointers in C++? + +In C++, both references and pointers are used to refer to memory locations, but they have different properties and uses. + +- **References**: An alias for another variable. +- **Pointers**: A variable that holds the memory address of another variable. + + + +## 2. Declaring References and Pointers + +### Declaring References + +A reference is declared using the `&` operator. + +**Syntax:** + +```cpp +datatype &referenceName = variableName; +``` + +**Example:** + +```cpp +#include +using namespace std; + +int main() { + int a = 10; + int &ref = a; // ref is a reference to a + cout << "a: " << a << endl; // Output: 10 + cout << "ref: " << ref << endl; // Output: 10 + return 0; +} +``` + +### Declaring Pointers + +A pointer is declared using the `*` operator. + +**Syntax:** + +```cpp +datatype *pointerName; +``` + +**Example:** + +```cpp +#include +using namespace std; + +int main() { + int a = 10; + int *ptr = &a; // ptr holds the address of a + cout << "a: " << a << endl; // Output: 10 + cout << "ptr: " << ptr << endl; // Output: address of a + cout << "*ptr: " << *ptr << endl; // Output: 10 + return 0; +} +``` + +## 3. Differences Between References and Pointers + +### 1. Syntax and Usage + +- **References**: Use the `&` operator for declaration and do not require dereferencing. +- **Pointers**: Use the `*` operator for declaration and require dereferencing with `*`. + +**Example:** + +```cpp +int a = 5; +int &ref = a; // Reference +int *ptr = &a; // Pointer +``` + +### 2. Initialization + +- **References**: Must be initialized when declared. +- **Pointers**: Can be declared without initialization and assigned later. + +**Example:** + +```cpp +int a = 5; +int &ref = a; // Must be initialized +int *ptr; // Can be declared without initialization +ptr = &a; // Assigned later +``` + +### 3. Reassignment + +- **References**: Cannot be reassigned to refer to another variable. +- **Pointers**: Can be reassigned to point to different variables. + +**Example:** + +```cpp +int a = 5, b = 10; +int &ref = a; // Reference to a +// ref = b; // Error: Cannot reassign a reference + +int *ptr = &a; // Pointer to a +ptr = &b; // Pointer reassigned to b +``` + +### 4. Null Values + +- **References**: Cannot be null. +- **Pointers**: Can be null (useful to indicate that they are not pointing to any valid memory). + +**Example:** + +```cpp +int a = 5; +int &ref = a; // Reference cannot be null + +int *ptr = nullptr; // Pointer can be null +ptr = &a; // Pointer assigned to a valid address +``` + +### 5. Memory Address + +- **References**: Implicitly provide the memory address of the referenced variable. +- **Pointers**: Explicitly hold and can be used to manipulate memory addresses. + +**Example:** + +```cpp +int a = 5; +int &ref = a; // Reference to a +int *ptr = &a; // Pointer to a + +cout << "Address of a: " << &a << endl; +cout << "Address using ref: " << &ref << endl; +cout << "Address using ptr: " << ptr << endl; +``` + +## 4. When to Use References and Pointers + +### Use References: +- When you need an alias for another variable. +- When you want to avoid null checks and pointer arithmetic. +- For pass-by-reference in function arguments to avoid copying large objects. + +### Use Pointers: +- When you need to allocate memory dynamically. +- When you need to implement data structures like linked lists, trees, etc. +- When you need to use null values to indicate "no object". + +## 5. Examples + +### Example 1: Using References + +```cpp +#include +using namespace std; + +void increment(int &ref) { + ref++; +} + +int main() { + int a = 10; + increment(a); + cout << "a: " << a << endl; // Output: 11 + return 0; +} +``` +### Example 2: Using Pointers +```cpp +#include +using namespace std; +void increment(int *ptr) { + (*ptr)++; +} +int main() { + int a = 10; + increment(&a); + cout << "a: " << a << endl; // Output: 11 + return 0; +} +``` + +## 6. Conclusion + +Both references and pointers are powerful features in C++ that allow you to manipulate memory and create more efficient programs. Understanding the differences between them and knowing when to use each is crucial for effective C++ programming From faba29175f1080c9add61346bad0b3e6ff996ec9 Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:36:01 +0530 Subject: [PATCH 5/9] Update pointers.md --- docs/programming-fundamentals/pointers.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/programming-fundamentals/pointers.md b/docs/programming-fundamentals/pointers.md index c0d99b508..4021917f0 100644 --- a/docs/programming-fundamentals/pointers.md +++ b/docs/programming-fundamentals/pointers.md @@ -1,3 +1,10 @@ +id: programming-fundamentals +title: References and Pointers +sidebar_label: Introduction to Declaring References +sidebar_position: 2 +description: 'Both references and pointers are powerful features in C++ that allow you to manipulate memory and create more efficient programs. Understanding the differences between them and knowing when to use each is crucial for effective C++ programming.' +tags: [dsa, data-structures, References and Pointers] + ## 1. What are References and Pointers in C++? In C++, both references and pointers are used to refer to memory locations, but they have different properties and uses. From 341cfa79a15cf2c8b53c5d5ced9304ead7aafe88 Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 15:43:52 +0530 Subject: [PATCH 6/9] Delete README.md --- README.md | 279 ------------------------------------------------------ 1 file changed, 279 deletions(-) delete mode 100644 README.md diff --git a/README.md b/README.md deleted file mode 100644 index e7ec7869d..000000000 --- a/README.md +++ /dev/null @@ -1,279 +0,0 @@ -# [Algo](https://ajay-dhangar.github.io/algo/) - Open Source Algorithm Repository - -Welcome to **Algo**, an open-source project that provides developers with algorithmic solutions and resources. Whether you're a beginner or an experienced coder, you can contribute, learn, and grow with us! 🚀 - -## Project Overview - -Algo provides a collection of well-documented algorithmic solutions written in various programming languages, covering a range of topics like sorting, searching, dynamic programming, and more. - -### Pick up Topics - -- [DSA Roadmap](https://roadmap.sh/datastructures-and-algorithms) - -We aim to: -- Create an extensive library of algorithms in different languages -- Help developers learn algorithmic problem-solving -- Foster open-source contribution and collaboration - -## Features - -- **Multi-language Support**: Algorithms in multiple programming languages -- **Beginner-Friendly**: Well-structured, easy-to-understand explanations -- **Open Source Contributions**: Welcoming developers at all levels to contribute -- **Community Forum**: A new interactive platform where developers can ask questions, share ideas, and collaborate in real-time. This forum will help bridge the gap between beginners and experts, allowing for deeper engagement and problem-solving. - -## Website - -This website is built using [Docusaurus 3](https://docusaurus.io/), a modern static website generator. - -## Installation - -```bash -$ npm install -``` - -## Local Development - -```bash -$ npm start -``` - -This command starts a local development server and opens a browser window. Most changes are reflected live without having to restart the server. - -## Build - -```bash -$ npm run build -``` - -This command generates static content into the `build` directory, which can be served using any static content hosting service. - -## Deployment - -### Using SSH: - -```bash -$ USE_SSH=true npm run deploy -``` - -### Not using SSH: - -```bash -$ GIT_USER= npm run deploy -``` - -If you are using GitHub Pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. - -## Contributing - -We welcome contributions from developers of all experience levels. Please refer to the [CONTRIBUTING.md](./CONTRIBUTING.md) file for guidelines. - -## Our Valuable Contributors ❤️✨ - -We are grateful to all the contributors who have helped improve this project. Your contributions are what make this project better! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - ajay-dhangar -
- Ajay Dhangar -
-
- - pavitraag -
- Pavitraa G -
-
- - Ankitha2130 -
- Ankitha R -
-
- - AbhijitMotekar99 -
- Abhijit Motekar -
-
- - T-Rahul-prabhu-38 -
- t rahul prabhu -
-
- - ananyag309 -
- Ananya Gupta -
-
- - narendra-dhangar -
- Narendra Dhangar -
-
- - IRFANSARI -
- Irfan Ansari -
-
- - yashksaini-coder -
- Yash Kumar Saini -
-
- - Shariq2003 -
- Shariq -
-
- - Soumya03007 -
- Soumyadeep Paul -
-
- - yogeswari05 -
- Chekka Yogeswari -
-
- - Hamza1821 -
- Hamza Mubin -
-
- - vedhcet-07 -
- Vishwas M D -
-
- - nishakp3005 -
- Nishita Panchal -
-
- - J-B-Mugundh -
- Mugundh J B -
-
- - Bhum-ika -
- Bhumika Sharma -
-
- - Akki-58 -
- AJ -
-
- - Kratik1093 -
- Kratik Mandloi -
-
- - Mohith1490 -
- Mohith Singh -
-
- - shalini-bhandari -
- Shalini Bhandari -
-
- - iking07 -
- Harsh -
-
- - IRFANSARI2 -
- IRFANSARI2 -
-
- - ImgBotApp -
- Imgbot -
-
- - shubhagarwal1 -
- Shubh Agarwal -
-
- - oebelus -
- Oebelus -
-
- - rajatsinghal02 -
- Rajat singhal -
-
- From 52b6f2c72e7b004356bc8f4e0c95ea260ba752f6 Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:28:10 +0530 Subject: [PATCH 7/9] Update pointers.md --- docs/programming-fundamentals/pointers.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/docs/programming-fundamentals/pointers.md b/docs/programming-fundamentals/pointers.md index 4021917f0..c7f75f6af 100644 --- a/docs/programming-fundamentals/pointers.md +++ b/docs/programming-fundamentals/pointers.md @@ -1,9 +1,11 @@ +--- id: programming-fundamentals -title: References and Pointers -sidebar_label: Introduction to Declaring References +title: Operator Overloading +sidebar_label: Introduction to Operator Overloading sidebar_position: 2 -description: 'Both references and pointers are powerful features in C++ that allow you to manipulate memory and create more efficient programs. Understanding the differences between them and knowing when to use each is crucial for effective C++ programming.' -tags: [dsa, data-structures, References and Pointers] +description: 'Operator overloading allows you to redefine the way operators work for user-defined types (classes and structs). It enables you to specify more intuitive ways to perform operations on objects of your classes.' +tags: [dsa, data-structures, Operator Overloading] +--- ## 1. What are References and Pointers in C++? From 986d13ed05ed1954610ddb0d9a8d065eecf8151e Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:29:38 +0530 Subject: [PATCH 8/9] Update pointers.md --- docs/programming-fundamentals/pointers.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/programming-fundamentals/pointers.md b/docs/programming-fundamentals/pointers.md index c7f75f6af..b46f55f45 100644 --- a/docs/programming-fundamentals/pointers.md +++ b/docs/programming-fundamentals/pointers.md @@ -1,10 +1,10 @@ --- id: programming-fundamentals -title: Operator Overloading -sidebar_label: Introduction to Operator Overloading +title: References and Pointers in C++ +sidebar_label: Introduction to References and Pointers sidebar_position: 2 -description: 'Operator overloading allows you to redefine the way operators work for user-defined types (classes and structs). It enables you to specify more intuitive ways to perform operations on objects of your classes.' -tags: [dsa, data-structures, Operator Overloading] +description: 'Both references and pointers are powerful features in C++ that allow you to manipulate memory and create more efficient programs. Understanding the differences between them and knowing when to use each is crucial for effective C++ programming' +tags: [dsa, data-structures, Pointers] --- ## 1. What are References and Pointers in C++? From 7e1770dd8e84819463da3b68fbcd5b616ac10d4f Mon Sep 17 00:00:00 2001 From: Nishant Dwivedi <135944619+nishant4500@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:35:44 +0530 Subject: [PATCH 9/9] Create README.md --- README.md | 367 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 367 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 000000000..2dc179f6d --- /dev/null +++ b/README.md @@ -0,0 +1,367 @@ +# [Algo](https://ajay-dhangar.github.io/algo/) - Open Source Algorithm Repository + +Welcome to **Algo**, an open-source project that provides developers with algorithmic solutions and resources. Whether you're a beginner or an experienced coder, you can contribute, learn, and grow with us! 🚀 + +## Project Overview + +Algo provides a collection of well-documented algorithmic solutions written in various programming languages, covering a range of topics like sorting, searching, dynamic programming, and more. + +### Pick up Topics + +- [DSA Roadmap](https://roadmap.sh/datastructures-and-algorithms) + +We aim to: +- Create an extensive library of algorithms in different languages +- Help developers learn algorithmic problem-solving +- Foster open-source contribution and collaboration + +## Features + +- **Multi-language Support**: Algorithms in multiple programming languages +- **Beginner-Friendly**: Well-structured, easy-to-understand explanations +- **Open Source Contributions**: Welcoming developers at all levels to contribute +- **Community Forum**: A new interactive platform where developers can ask questions, share ideas, and collaborate in real-time. This forum will help bridge the gap between beginners and experts, allowing for deeper engagement and problem-solving. + +## Website + +This website is built using [Docusaurus 3](https://docusaurus.io/), a modern static website generator. + +## Installation + +```bash +$ npm install +``` + +## Local Development + +```bash +$ npm start +``` + +This command starts a local development server and opens a browser window. Most changes are reflected live without having to restart the server. + +## Build + +```bash +$ npm run build +``` + +This command generates static content into the `build` directory, which can be served using any static content hosting service. + +## Deployment + +### Using SSH: + +```bash +$ USE_SSH=true npm run deploy +``` + +### Not using SSH: + +```bash +$ GIT_USER= npm run deploy +``` + +If you are using GitHub Pages for hosting, this command is a convenient way to build the website and push to the `gh-pages` branch. + +## Contributing + +We welcome contributions from developers of all experience levels. Please refer to the [CONTRIBUTING.md](./CONTRIBUTING.md) file for guidelines. + +## Our Valuable Contributors ❤️✨ + +We are grateful to all the contributors who have helped improve this project. Your contributions are what make this project better! + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + ajay-dhangar +
+ Ajay Dhangar +
+
+ + pavitraag +
+ Pavitraa G +
+
+ + T-Rahul-prabhu-38 +
+ t rahul prabhu +
+
+ + Ankitha2130 +
+ Ankitha R +
+
+ + AbhijitMotekar99 +
+ Abhijit Motekar +
+
+ + Shariq2003 +
+ Shariq +
+
+ + ananyag309 +
+ Ananya Gupta +
+
+ + kRajoria121 +
+ Kundan Rajoria +
+
+ + yashksaini-coder +
+ Yash Kumar Saini +
+
+ + IRFANSARI +
+ Irfan Ansari +
+
+ + tanushrigoel +
+ tanushrigoel +
+
+ + Soumya03007 +
+ Soumyadeep Paul +
+
+ + narendra-dhangar +
+ Narendra Dhangar +
+
+ + yogeswari05 +
+ Chekka Yogeswari +
+
+ + Hamza1821 +
+ Hamza Mubin +
+
+ + shalini-bhandari +
+ Shalini Bhandari +
+
+ + monishkumardvs +
+ monishkumardvs +
+
+ + vedhcet-07 +
+ Vishwas M D +
+
+ + PRASHANTSWAROOP001 +
+ PRASHANT SWAROOP +
+
+ + nishakp3005 +
+ Nishita Panchal +
+
+ + J-B-Mugundh +
+ Mugundh J B +
+
+ + Himanshi-m +
+ Himanshi Maheshwari +
+
+ + Bhum-ika +
+ Bhumika Sharma +
+
+ + Anandha-Vihari +
+ Anandha-Vihari +
+
+ + sriraghavi22 +
+ sriraghavi22 +
+
+ + Mohith1490 +
+ Mohith Singh +
+
+ + Kratik1093 +
+ Kratik Mandloi +
+
+ + Akki-58 +
+ AJ +
+
+ + 4F24L +
+ Md Afzal Mir +
+
+ + iking07 +
+ Harsh +
+
+ + IRFANSARI2 +
+ IRFANSARI2 +
+
+ + ImgBotApp +
+ Imgbot +
+
+ + jvkousthub +
+ Kousthub J V +
+
+ + shubhagarwal1 +
+ Shubh Agarwal +
+
+ + oebelus +
+ Oebelus +
+
+ + Rahul7raj +
+ Rahul7raj +
+
+ + rajatsinghal02 +
+ Rajat singhal +
+
+ + RchtDshr +
+ Rachita Dashore +
+
+ + nishant4500 +
+ nishant4500 +
+
+