Advertisement
Guest User

MST disneyland

a guest
Apr 28th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib> //needed for atoi for linux box dev, not automatically put in global scope
  3. #include <fstream>
  4. #include <string>
  5. #include <list>
  6. using namespace std;
  7. string* parseLine(string*,string,char);
  8.  
  9.  
  10. string* parseLine(string* ary,string line,char delim)
  11. {
  12.     unsigned int i = 0 ;
  13.     unsigned int beg = 0;
  14.     unsigned int end = 0;
  15.    
  16.     for(; end < line.length(); end++)
  17.     {
  18.         if(line[end] == delim)
  19.         {
  20.             ary[i++] = line.substr(beg,end-beg);
  21.             end += 1;
  22.             beg = end;
  23.         }
  24.         if(line.length()-1 == end)
  25.             ary[i++] = line.substr(beg,end-beg+1);
  26.     }
  27.     return ary;
  28. }
  29.    
  30.  
  31.  
  32.  
  33.  
  34.  
  35. int main(){
  36.     list<string*> rVert;
  37.     list<string*> tVert;
  38.     int counter = 0;
  39.     int total = 0;
  40.     string* infoVert;
  41.     string* temp;
  42.     ifstream data;
  43.     data.open("disneyland.txt");
  44.     string output;
  45.     string total_nodes = "";
  46.     string* temp2;
  47.    
  48.    
  49.    
  50.        
  51.    
  52.     if (data.is_open()) {
  53.         while (!data.eof()) {
  54.             if (counter == 0) //grabbing the total amount of vertcies
  55.             {
  56.                  getline(data,output);
  57.                  total = atoi(output.c_str());
  58.                
  59.             }else{ // now parsing line into an array then pushing it into the remaining list.
  60.                 infoVert = new string[4];
  61.                 getline(data,output);
  62.                 temp = parseLine(infoVert,output,' ');
  63.                 cout << "id: " << temp[0] << " ,x: " << temp[1] << " ,y: " << temp[2] << " ,name: " << temp[3] << endl;
  64.                 rVert.push_front(temp);
  65.                 delete [] infoVert;
  66.             }
  67.             counter++;
  68.         }
  69.     }
  70.    
  71.     //---------------------
  72.     //cleaning up the mess.
  73.     data.close();
  74.    
  75.     //---------------------
  76.    
  77.     while(!rVert.empty())
  78.     {
  79.         temp2 = rVert.front();
  80.        
  81.         cout << "id: " << temp2[0] << " ,x: " << temp2[1] << " ,y: " << temp2[2] << " ,name: " << temp2[3] << endl;
  82.         rVert.pop_front();
  83.     }
  84.    
  85.     return 0;
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement