Advertisement
Guest User

Untitled

a guest
Mar 21st, 2013
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1.  
  2. //These are the nodes
  3.  
  4. head_insert(head, "Jam",  12, 9, 2003);
  5. head_insert(head, "Tea",  10, 8, 2003);  
  6. head_insert(head, "Rolls", 1,1,2010);
  7.  
  8. //This is the search in main
  9.  
  10. int d, m, y;
  11.     cout << "Enter the month, day, and year (seperated by pressing enter):" << endl;
  12.     cin >> m;
  13.     cin >> d;
  14.     cin >> y;
  15.        if (search_date(head, m, d, y))
  16.        cout << m <<"/" << d <<"/" << y << " is on the list." << endl;
  17.     else
  18.        cout << m <<"/" << d <<"/" << y << " is not on the list." << endl;
  19.  
  20.  
  21.  
  22.  
  23. // This is the function that searches for the expiration date
  24.  
  25. NodePtr search_date(NodePtr head, int month, int day, int year)
  26. {
  27.    // Point to the head node
  28.     NodePtr here = head;
  29.     // If the list is empty nothing to search
  30.     if (here == NULL)
  31.     {
  32.         return NULL;
  33.     }
  34.     // Search for the item    
  35.    
  36.     else{
  37.         //while you have still items and you haven't found the target yet
  38.         while (here-> Exp.day != day && here-> Exp.month != month  &&  here->Exp.year != year  && here->link != NULL  )
  39.            
  40.             here = here->link;
  41.            
  42.         // Found the target, return the pointer at that location
  43.         if (here-> Exp.month == month && here-> Exp.day == day && here-> Exp.year == year  )
  44.            
  45.             return here;
  46.            
  47.         // Search unsuccessful, return Null
  48.         else
  49.             return NULL;
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement