SHARE
TWEET

Untitled

a guest Nov 12th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct list_node {
  2.     train* data;
  3.     list_node* next;
  4. }
  5.  
  6. struct train {
  7.     string destination;
  8.     int id;
  9.     unsigned int arrivalTime;
  10. }
  11.  
  12. class TrainList {
  13.     list_node *head;
  14.  
  15. public:
  16.     TrainList() {head = NULL;}
  17.     ~TrainList();
  18.  
  19.     bool checkTrainIdValid(int id);
  20.     void add();
  21.     void remove();
  22.     void show();
  23.  
  24.     void save();
  25.     void load();
  26. }
  27.  
  28. TrainList::~TrainList() {
  29.     while (head != NULL) {
  30.         list_node *tmp = head->next;
  31.         delete head;
  32.         head = tmp;
  33.     }
  34. }
  35.  
  36. bool TrainList::checkTrainIdValid(int id) {
  37.     list_node *iter = head;
  38.     while (iter != NULL) {
  39.         if (iter->id == id) {
  40.             cerr << "Train with such id already exists!!!" << endl;
  41.             return false;
  42.         }
  43.     }
  44.  
  45.     return true;
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top