fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4. struct Node{
  5. string mail;
  6. Node* next;
  7.  
  8. };
  9. class LinkedList{
  10. public:
  11. Node* head;
  12. Node* tail;
  13. LinkedList(){
  14. head = nullptr;
  15. tail = nullptr;
  16. }
  17. void printAllMails(){
  18. Node* temp = head;
  19. while(temp != nullptr){
  20. cout << temp->mail << endl;
  21. temp = temp->next;
  22. }
  23. }
  24. bool searchForMail(string email){
  25. Node* temp = head;
  26. while(temp != nullptr){
  27. if(temp->mail == email){
  28. return true;
  29. }
  30. temp = temp->next;
  31. }
  32. return false;
  33. }
  34. bool addMail(string email){
  35. if(searchForMail(email)){
  36. return false;
  37. }
  38. Node* newMailNode = new Node();
  39. newMailNode->mail = email;
  40. newMailNode->next = nullptr;
  41. if(head == nullptr){
  42. head = newMailNode;
  43. tail = newMailNode;
  44. }else{
  45. tail->next = newMailNode;
  46. tail = newMailNode;
  47. }
  48. return true;
  49. }
  50. };
  51. int main() {
  52. cout << "Hello, World!" << std::endl;
  53. LinkedList linkedList;
  54. linkedList.addMail("mail1");
  55. linkedList.addMail("mail2");
  56. linkedList.addMail("mail3");
  57. linkedList.printAllMails();
  58. bool isFound = linkedList.searchForMail("mail4");
  59. cout<<isFound<<endl;
  60. return 0;
  61. }
  62.  
Success #stdin #stdout 0.01s 5312KB
stdin
Standard input is empty
stdout
Hello, World!
mail1
mail2
mail3
0