Click here to Skip to main content
15,885,141 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
#include <iostream>
#include<vector>
#include<list>
#include<fstream>
#include<cstring>

using namespace std;

const int n=6;

struct graph
{
    int vertices;
    char typ;
    char nodes[10];
} ;

struct node
{
    
    char str[10];
};

int main(int argc, char* argv[2])
{
    list<node> l;
   std::vector<list><node> >  adjlist[n];
  
   int i, degree[20];
   char ch, ch1,ch2;
   struct graph g1;
   g1=new graph;
   ifstream fin;
  
   fin.open(argv[1]);
  
   fin>> g1.vertices;
   fin>>ch;
   fin>> g1.typ;
  
   for(i=0; i <  g1.vertices-1  ;  i++   )
   {
       fin>> g1.nodes[i];
       fin>>ch;
      
   }
  
   fin>>g1.nodes[i];
  
   while(!fin.eof())
   {
       fin>>ch;
       fin>>ch1;
       fin>>ch2;
      
       for(i=0; i<g1.vertices;>       {
           if(g1.nodes[i]==ch)
           {
               degree[i]=degree[i]+1;
               adjlist[i].push_back(ch2);
               break;
           }
       }
      
      if(g1.typ=='u')
      {
           for(i=0; i<g1.vertices;>       {
           if(g1.nodes[i]==ch2)
           {
               degree[i]=degree[i]+1;
               break;
           }
      }
      
   }
   
   } 
   ofstream fout;
   fout.open(argv[2]);
   
   for(i=0; i< g1.vertices; i++)
   {
       fout<<g1.nodes[i];
       fout<<"," ;
       fout<<degree[i];
       fout<<"\n";
      
   }
   
   
  fout.close();
  fin.close();
  
   return 0;
}
Posted
Updated 2-May-15 4:27am
v3
Comments
nv3 2-May-15 9:08am    
Next time, please format your code properly with <pre> tags. I have done it for you this time.

Now, what's wrong with your code? What is your question? We cannot see your screen. So you have to be a little more specific than just posting the question of your homework.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900