title: C++ Creating a Weighted Graph?
body: <p>How do I create a C++ weighted Graph where each vertex in the graph has a weight (some integer value)?</p>
  
  <p>You can download my graph project <a href="http://rapidshare.com/files/317273914/Graphs.rar.html" rel="noreferrer">here</a> (RapidShare):</p>
  
  <p>Here is the function to create a graph from graph data stored in a text file:</p>
  
  <pre><code>void GraphType::createGraph()
  {
      ifstream infile;
      char fileName[50];
  
      int index;
      int vertex;
      int adjacentVertex;
  
      if(gSize != 0)
          clearGraph();
  
      cout &lt;&lt; "Enter input file name: ";
      cin &gt;&gt; fileName;
      cout &lt;&lt; endl;
  
      infile.open(fileName);
  
      if(!infile)
      {
              cout &lt;&lt; "Cannot open input file." &lt;&lt; endl;
              return;
      }
  
      infile &gt;&gt; gSize;
  
      graph = new UnorderedLinkList[gSize];
  
      for(index = 0; index &lt; gSize; index++)
      {
              infile &gt;&gt; vertex;
              infile &gt;&gt; adjacentVertex;
  
              while(adjacentVertex != -999)
              {
                  graph[ vertex ].insertLast(adjacentVertex);
                  infile &gt;&gt; adjacentVertex;
              }
      }
      infile.close();
  }
  </code></pre>
  
  <p>And here is the Graph data (number of vertices = 10, vertex 0 to 9 and adjacent vertices) input from text file "Network2.txt":</p>
  
  <blockquote>
    <p>10</p>
    
    <p>0 1 2 9 -999</p>
    
    <p>1 0 2 -999</p>
    
    <p>2 0 1 9 8 3 -999</p>
    
    <p>3 2 8 5 -999</p>
    
    <p>4 3 8 6 5 -999</p>
    
    <p>5 4 6 7 -999</p>
    
    <p>6 4 7 8 -999</p>
    
    <p>7 8 6 5 -999</p>
    
    <p>8 9 2 3 4 6 7 -999</p>
    
    <p>9 0 2 8 -999</p>
  </blockquote>
  
  <p>My question is, how do i assign a unique value or weight to vertices 0 to 9? Any assistance will be really appreciated. Thanks in advance!</p>