Advertisement
Guest User

Untitled

a guest
Oct 24th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. #include "List.h"
  2. #include <vector>
  3. #include <iostream>
  4. #include <sstream>
  5. #include <string>
  6. #include <iterator>
  7. #include <deque>
  8. #include <algorithm>
  9. #include <cstdlib>
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     // Create list
  16.     List Borna;
  17.  
  18.     // Take input from user
  19.     std::string input;
  20.     getline(std::cin, input);
  21.  
  22.     // Seperate input by space, and put in cells in vector named inputvector that holds strings
  23.     std::stringstream ss(input);
  24.     std::istream_iterator<std::string> begin(ss);
  25.     std::istream_iterator<std::string> end;
  26.     std::vector<std::string> inputvector(begin, end);
  27.  
  28.     //std::cout << (inputvector.at(1)).at(0) << std::endl;
  29.  
  30.     for(unsigned long i = 0; i < inputvector.size(); i++)
  31.     {
  32.             // If input is R, then remove from head
  33.         if (inputvector.at(i) == "R")
  34.         {
  35.             if (inputvector.at(0) == "R") {
  36.  
  37.                 inputvector.at(0).erase(0, 1);
  38.                 continue;
  39.  
  40.                 }
  41.             //std::cout << "Removing value " << std::endl;
  42.             Borna.RemoveFromHead();
  43.         }
  44.  
  45.             // If input is not R, then it must be A; So, remove the A from the stringint combination
  46.             // and add the integer to the node list
  47.         else
  48.         {
  49.             (inputvector.at(i)).erase(0, 1);
  50.             string s = inputvector.at(i);
  51.             int x = 0;
  52.             stringstream convert(s);
  53.             convert>>x;
  54.  
  55.             //std::cout << "Adding value " << inputvector.at(i) << std::endl;
  56.             Borna.AddNode(x);
  57.         }
  58.  
  59.     }
  60.  
  61.  
  62.     Borna.PrintList();
  63.     //std::cout << "test" << std::endl;
  64.     Borna.FindMiddle();
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement