Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. HubNode *hh = NULL;
  2. HubNode **head;
  3. *head = hh;
  4. Tools::loadHubs(head);
  5. cout << hh->name; /* HubNodes have a string called "name" */
  6.  
  7. void Tools::loadHubs(HubNode **head)
  8. {
  9. string line, name, location;
  10. // headFlights = currFlights = prevFlights = NULL;
  11.  
  12. ifstream myfile("Hub.csv");
  13. if (myfile.is_open())
  14. {
  15. while (getline(myfile, line)) {// Omit the Caption Line.
  16. while (getline(myfile, name, ','))//Get every value in order.
  17. {
  18. getline(myfile, location, 'n');
  19. // cout << line << "n";
  20. // cout << name << "n";
  21. // cout << location << "n";
  22. HubNode::AddHub(name, location, head);
  23. }
  24. }
  25. myfile.close();
  26. }
  27. else { cout << "nUnable to open filen"; }
  28. }
  29.  
  30. void HubNode::AddHub(string sname, string slocation, HubNode **head)
  31. {
  32. HubNode* newNode = new HubNode;
  33. HubNode *point;
  34.  
  35. newNode->next = NULL;
  36. newNode->name = sname;
  37. newNode->location = slocation;
  38.  
  39. if (*head != NULL)
  40. {
  41. HubNode *curr = *head;
  42. while (curr->next != NULL)
  43. {
  44. curr = curr->next;
  45. }
  46. curr->next = newNode;
  47. }
  48. else
  49. {
  50. point = newNode;
  51. *head = point;
  52. }
  53. }
  54.  
  55. int value = 10;
  56. int *p;
  57. *p = value;
  58.  
  59. HubNode *hh = NULL;
  60. HubNode **head;
  61. *head = hh;
  62.  
  63. HubNode *hh = NULL;
  64. Tools::loadHubs(&hh);
  65. cout << hh->name;
  66.  
  67. void HubNode::AddHub(const string& sname, const string& slocation, HubNode **head)
  68. {
  69. HubNode* newNode = new HubNode;
  70. newNode->next = NULL;
  71. newNode->name = sname;
  72. newNode->location = slocation;
  73.  
  74. while (*head)
  75. head = &(*head)->next;
  76.  
  77. *head = newNode;
  78. }
  79.  
  80. void HubNode::AddHub(const string& sname, const string& slocation, HubNode **head)
  81. {
  82. while (*head)
  83. head = &(*head)->next;
  84. *head = new HubNode(sname, slocation);
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement