Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add endlines in hashing/chaining.cpp #1559

Merged
merged 1 commit into from
Aug 15, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions hashing/chaining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ class hash_chain {
if (!head[i]) {
std::cout << "Key " << i << " is empty" << std::endl;
} else {
std::cout << "Key " << i << " has values = ";
std::cout << "Key " << i << " has values = " << std::endl;
temp = head[i];
while (temp->next) {
std::cout << temp->data << " ";
std::cout << temp->data << " " << std::endl;
temp = temp->next;
}
std::cout << temp->data;
Expand Down Expand Up @@ -102,27 +102,27 @@ class hash_chain {
std::shared_ptr<Node> temp = head[h];
if (!head[h]) {
// index does not exist!
std::cout << "Element not found";
std::cout << "Element not found" << std::endl;
return false;
}

// scan for data value
while (temp->data != x && temp->next) temp = temp->next;

if (temp->next) {
std::cout << "Element found";
std::cout << "Element found" << std::endl;
return true;
}

// implicit else condition
// i.e., temp->next == nullptr
if (temp->data == x) {
std::cout << "Element found";
std::cout << "Element found" << std::endl;
return true;
}

// further implicit else condition
std::cout << "Element not found";
std::cout << "Element not found" << std::endl;
return false;
}
};
Expand All @@ -132,7 +132,7 @@ class hash_chain {
*/
int main() {
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;

hash_chain mychain(mod);
Expand All @@ -149,22 +149,22 @@ int main() {
std::cin >> c;
switch (c) {
case 1:
std::cout << "Enter element to add = ";
std::cout << "Enter element to add = " << std::endl;
std::cin >> x;
h = mychain.hash(x);
h = std::abs(h);
mychain.add(x, h);
break;
case 2:
std::cout << "Enter element to search = ";
std::cout << "Enter element to search = " << std::endl;
std::cin >> x;
h = mychain.hash(x);
mychain.find(x, h);
break;
case 3:
std::cout << "Enter element to generate hash = ";
std::cout << "Enter element to generate hash = " << std::endl;
std::cin >> x;
std::cout << "Hash of " << x << " is = " << mychain.hash(x);
std::cout << "Hash of " << x << " is = " << mychain.hash(x) << std::endl;
break;
case 4:
mychain.display();
Expand Down