mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
Merge branch 'master' into os
This commit is contained in:
commit
bdeee3da68
@ -15,13 +15,13 @@
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
The repository is a collection of open-source implementation of a variety of algorithms implemented in C++ and licensed under [MIT License](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/LICENSE). The algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and the associated documentation are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using a different algorithm strategies and optimizations.
|
The repository is a collection of open-source implementation of a variety of algorithms implemented in C++ and licensed under [MIT License](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/LICENSE). These algorithms span a variety of topics from computer science, mathematics and statistics, data science, machine learning, engineering, etc.. The implementations and the associated documentation are meant to provide a learning resource for educators and students. Hence, one may find more than one implementation for the same objective but using a different algorithm strategies and optimizations.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
* The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - [C++](https://en.wikipedia.org/wiki/C%2B%2B).
|
* The repository provides implementations of various algorithms in one of the most fundamental general purpose languages - [C++](https://en.wikipedia.org/wiki/C%2B%2B).
|
||||||
* Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
|
* Well documented source code with detailed explanations provide a valuable resource for educators and students alike.
|
||||||
* Each source code is atomic using [STL classes](https://en.wikipedia.org/wiki/Standard_Template_Library) and _no external libraries_ are required for their compilation and execution. Thus the fundamentals of the algorithms can be studied in much depth.
|
* Each source code is atomic using [STL classes](https://en.wikipedia.org/wiki/Standard_Template_Library) and _no external libraries_ are required for their compilation and execution. Thus, the fundamentals of the algorithms can be studied in much depth.
|
||||||
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C-Plus-Plus/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.0 respectively.
|
* Source codes are [compiled and tested](https://github.com/TheAlgorithms/C-Plus-Plus/actions?query=workflow%3A%22Awesome+CI+Workflow%22) for every commit on the latest versions of three major operating systems viz., Windows, MacOS and Ubuntu (Linux) using MSVC 16 2019, AppleClang 11.0 and GNU 7.5.0 respectively.
|
||||||
* Strict adherence to [C++11](https://en.wikipedia.org/wiki/C%2B%2B11) standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
|
* Strict adherence to [C++11](https://en.wikipedia.org/wiki/C%2B%2B11) standard ensures portability of code to embedded systems as well like ESP32, ARM Cortex, etc. with little to no changes.
|
||||||
* Self-checks within programs ensure correct implementations with confidence.
|
* Self-checks within programs ensure correct implementations with confidence.
|
||||||
|
@ -67,10 +67,10 @@ class hash_chain {
|
|||||||
if (!head[i]) {
|
if (!head[i]) {
|
||||||
std::cout << "Key " << i << " is empty" << std::endl;
|
std::cout << "Key " << i << " is empty" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
std::cout << "Key " << i << " has values = ";
|
std::cout << "Key " << i << " has values = " << std::endl;
|
||||||
temp = head[i];
|
temp = head[i];
|
||||||
while (temp->next) {
|
while (temp->next) {
|
||||||
std::cout << temp->data << " ";
|
std::cout << temp->data << " " << std::endl;
|
||||||
temp = temp->next;
|
temp = temp->next;
|
||||||
}
|
}
|
||||||
std::cout << temp->data;
|
std::cout << temp->data;
|
||||||
@ -102,7 +102,7 @@ class hash_chain {
|
|||||||
std::shared_ptr<Node> temp = head[h];
|
std::shared_ptr<Node> temp = head[h];
|
||||||
if (!head[h]) {
|
if (!head[h]) {
|
||||||
// index does not exist!
|
// index does not exist!
|
||||||
std::cout << "Element not found";
|
std::cout << "Element not found" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,19 +110,19 @@ class hash_chain {
|
|||||||
while (temp->data != x && temp->next) temp = temp->next;
|
while (temp->data != x && temp->next) temp = temp->next;
|
||||||
|
|
||||||
if (temp->next) {
|
if (temp->next) {
|
||||||
std::cout << "Element found";
|
std::cout << "Element found" << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// implicit else condition
|
// implicit else condition
|
||||||
// i.e., temp->next == nullptr
|
// i.e., temp->next == nullptr
|
||||||
if (temp->data == x) {
|
if (temp->data == x) {
|
||||||
std::cout << "Element found";
|
std::cout << "Element found" << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// further implicit else condition
|
// further implicit else condition
|
||||||
std::cout << "Element not found";
|
std::cout << "Element not found" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -132,7 +132,7 @@ class hash_chain {
|
|||||||
*/
|
*/
|
||||||
int main() {
|
int main() {
|
||||||
int c = 0, x = 0, mod = 0, h = 0;
|
int c = 0, x = 0, mod = 0, h = 0;
|
||||||
std::cout << "Enter the size of Hash Table. = ";
|
std::cout << "Enter the size of Hash Table. = " << std::endl;
|
||||||
std::cin >> mod;
|
std::cin >> mod;
|
||||||
|
|
||||||
hash_chain mychain(mod);
|
hash_chain mychain(mod);
|
||||||
@ -149,22 +149,22 @@ int main() {
|
|||||||
std::cin >> c;
|
std::cin >> c;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 1:
|
case 1:
|
||||||
std::cout << "Enter element to add = ";
|
std::cout << "Enter element to add = " << std::endl;
|
||||||
std::cin >> x;
|
std::cin >> x;
|
||||||
h = mychain.hash(x);
|
h = mychain.hash(x);
|
||||||
h = std::abs(h);
|
h = std::abs(h);
|
||||||
mychain.add(x, h);
|
mychain.add(x, h);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
std::cout << "Enter element to search = ";
|
std::cout << "Enter element to search = " << std::endl;
|
||||||
std::cin >> x;
|
std::cin >> x;
|
||||||
h = mychain.hash(x);
|
h = mychain.hash(x);
|
||||||
mychain.find(x, h);
|
mychain.find(x, h);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
std::cout << "Enter element to generate hash = ";
|
std::cout << "Enter element to generate hash = " << std::endl;
|
||||||
std::cin >> x;
|
std::cin >> x;
|
||||||
std::cout << "Hash of " << x << " is = " << mychain.hash(x);
|
std::cout << "Hash of " << x << " is = " << mychain.hash(x) << std::endl;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
mychain.display();
|
mychain.display();
|
||||||
|
Loading…
Reference in New Issue
Block a user