Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- struct Node
- {
- string name;
- Node * next;
- };
- int hashF(string str)
- {
- int temp = 0;
- for(int i = 0; i < str.length(); i++)
- {
- temp+=str[i];
- }
- temp = temp % 11;
- return temp;
- }
- void add(string name, Node* Tab[])
- {
- int count = hashF(name); //zeby nie wywolywac funkcji wiele razy
- if(Tab[count] -> name == "")
- {
- Tab[count]->name = name;
- Tab[count]->next = nullptr;
- }
- else
- {
- while(Tab[count] -> name != "")
- {
- if(Tab[count] -> next == nullptr)
- {
- Tab[count] -> next = new Node();
- }
- Tab[count] = Tab[count] -> next;
- }
- Tab[count]->name = name;
- cout << Tab[count]->name;
- Tab[count]->next = nullptr;
- }
- }
- void find(string name, Node * Tab[])
- {
- if(Tab[hashF(name)] -> name == name)
- {
- cout << Tab[hashF(name)] -> name << endl;
- }
- else
- {
- int count = hashF(name);
- while(Tab[count] -> name != name)
- {
- Tab[count] = Tab[count] -> next;
- }
- cout << Tab[count]->name << endl;
- }
- }
- int main()
- {
- Node * Tab[11];
- for(int i = 0; i < 11; i++)
- {
- Tab[i] = new Node();
- }
- add("Mia", Tab);
- add("Sue", Tab);
- find("Mia", Tab);
- // Tab[4] = Tab[4] -> next;
- // cout << Tab[4] -> next;
- for(int i = 0; i < 11; i++)
- {
- delete Tab[i];
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement