SHARE
TWEET

Untitled

a guest Jun 19th, 2017 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         case ISAFTER:
  2.             if (q.isEmpty()) { 
  3.                 cout << "Queue is Empty. Something can't be after nothing. :P\n";
  4.             }
  5.             else {
  6.             int user_after, user_data = 0;
  7.             /*else if (q.isAfter() == true)
  8.                 cout << */
  9.             cout << "Please enter your first integer value.\nThis value [1], if found, will check if the second entered value is after it:";
  10.                 cin >> user_after;
  11.                 cout << endl;
  12.                 //QueueNode( user_after ) a;
  13.                 cout << "Please enter your second integer value.\nAssuming [1] was found, isAfter will check if this value [2] is after [1]: ";
  14.                 cin >> user_data;
  15.                 cout << endl;
  16.                 //QueueNode( user_data ) d;
  17.                 if ( q.isAfter( user_data, user_after ))
  18.                     cout << user_data << " is after " << user_after << "in the Queue.\n";
  19.                 else
  20.                     cout << user_data << " was not found after a " << user_after << "in the Queue.\n";
  21.             }
  22.             break;
  23.  
  24. ////////////////////////////////////////////  isAfter() Implementation ////////////////////////////////////////
  25.  
  26. template <class Object>
  27. bool Queue<Object>::isAfter( Object data, Object after ) const {
  28. QueueNode<Object> *findsAfter = header;
  29. QueueNode<Object> *findsData = header;
  30. //checks for an empty list
  31. /*if( header->getNext() == NULL ) {
  32.     cout << "Queue is Empty. Something can't be after nothing. :P\n";
  33.     return(false);
  34.     }*/
  35. do {
  36.     findsAfter = findsAfter->getNext();
  37.     findsData = findsData->getNext();
  38.     if( findsAfter->getElement() == after ) {
  39.         do{
  40.         findsData = findsData->getNext();
  41.         if( findsData->getElement() == data )
  42.             return(true);
  43.         else if( findsData->getElement() == NULL )
  44.             return(false);
  45.         else
  46.             findsData = findsData->getNext();
  47.         } while ( findsData->getElement() != NULL );
  48.     }
  49. } while( findsAfter->getElement() != NULL );
  50. cout << "Value [1] was not found in the Queue.\n";
  51. return(false);
  52. }
RAW Paste Data
Want to get better at C++?
Learn to code C++ in 2017
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top