ok lets say i have the following text

T 2 X F
X 2 Y G
Y 1 Z
Z 2 G 1
I 3 T G E
F 2 I E

looking at the first line t is the vertex 2 is the number of edges it has and X and F are the edges connecting to T.

So im suppose to implement an adjacency list which will read a file and store it in array called info which contains vertexname, outdegree, and adjcency list.

i really need help how to correctly read the file and store the values into an array using link list class i have

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include "slist.h"
#include "ll.C"
using namespace std;

void getData();
void printData();

const int SIZE = 10;

struct info
  char vertexName;
  int outDegree;
  slist adjacentOnes; // this comes from slist.h which is a link list class                                                   

int main()


//PURPOSE: GETS DATA FROM THE FILE                                                                                            
void getData()
  info table[SIZE];

  ifstream fin;
      for(int i = 0; i < SIZE;i++)
          fin >> table[i].vertexName;
          fin >> table[i].outDegree;
          // this is where im kinda of lost, I have a slist class which is a      link list class                                  
          // i implemented and it works. It has a  member called addRear. addRear must be called                              
          // everytime a letter is read from the file.For how would i do this??   


void printData()

5 Years
Discussion Span
Last Post by israruval007

You'll need to post the code for your slist class...

Edited by tkud: n/a


ok well i have the getdata working i believe. and my slist contains a member addRear which adds an element at the rear of the link list.

having this, how could i display the table on my printData() function

void getData()
 info table[SIZE];                                               

  ifstream fin("table.txt");
  string line;
  for(int i = 0; i<SIZE && getline(fin, line); i++)
      istringstream s(line);
      s >> table[i].vertexName >> table[i].outDegree;
      char x;
      while(s >> x)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.