Algorithmen_Datenstrukturen/Uebung 4/Uebung4_2/main.cpp

53 lines
1.5 KiB
C++

#include "hashTable.h"
#include "pbEntry.h"
#include <iostream>
#include <string>
// Function to generate random strings for our Wares. See:
// https://stackoverflow.com/a/12468109
std::string random_string(size_t length) {
auto randchar = []() -> char {
const char charset[] = "0123456789";
const size_t max_index = (sizeof(charset) - 1);
return charset[rand() % max_index];
};
std::string str(length, 0);
std::generate_n(str.begin(), length, randchar);
return str;
}
int main() {
PbEntry entry1("3277971", "Norma Noe", "North Lyme Drive 30");
PbEntry entry2("9928657", "Ashok Kumar", "Lawrence Avenue 24");
PbEntry entry3("1674792", "Baby Doe", "North Lyme Street 34");
PbEntry entry4("4991459", "Brett Boe", "North Lyme Road 35 ");
PbEntry entry5("1990539", "Carla Coe", "Lawrence Road 29");
HashTable ht;
ht.insert(&entry1);
ht.insert(&entry2);
ht.insert(&entry3);
ht.insert(&entry4);
ht.insert(&entry5);
for (int i = 0; i < 60; i++) {
ht.insert(new PbEntry(random_string(7), "test", "test"));
}
ht.print();
std::cout << ht.getloadFactor() << std::endl;
// ht.setHashFunction("mod17");
// ht.insert(&entry1);
// ht.insert(&entry2);
// ht.insert(&entry3);
// ht.insert(&entry4);
// ht.insert(&entry5);
// ht.print();
// const PbEntry* s1 = ht.search("3277971");
// std::cout << s1->toString();
// bool test = ht.deleteItem("3277971");
// std::cout << test << std::endl;
// bool test2 = ht.deleteItem("3277971");
// std::cout << test2 << std::endl;
}