Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <iomanip>
- #include <string>
- using namespace std;
- const int maxv = 'M'+1;
- void initialize(int graph[maxv][maxv])
- {
- int i, j;
- for(i=0; i<maxv; i++)
- for(j=0; j<maxv;j++)
- graph[i][j]=0;
- }
- void read(int graph[maxv][maxv])
- {
- ifstream inf;
- inf.open("edge.dat");
- char V1, V2;
- int wt;
- while(!inf.eof())
- {
- inf >> V1 >> V2 >> wt;
- graph[V1][V2]=wt;
- graph[V2][V1]=wt;
- }
- }
- void print(int graph[maxv][maxv])
- {
- ofstream outf;
- outf.open("graph.out");
- int i, j;
- for(i=0; i<maxv; i++)
- {
- for(j=0; j<maxv; j++)
- outf << graph[i][j] << " " << endl;
- }
- }
- int main()
- {
- int graph[maxv][maxv];
- initialize(graph);
- read(graph);
- print(graph);
- }
Advertisement
Add Comment
Please, Sign In to add comment