Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <list>
- #include <iterator>
- #include <vector>
- using namespace std;
- class graph
- {
- int v;
- list <int> *adj;
- public:
- graph(int v)
- {
- this->v=v;
- adj=new list<int>[v];
- }
- void add_adj(int v,int w)
- {
- adj[v].push_back(w);
- }
- void find_ind()
- {
- vector <int>indegree(v,0);
- vector<int>::iterator it2;
- list<int>::iterator it;
- for(int i=0; i<v; i++)
- {
- int count=0;
- for(int j=0; j<v; j++)
- {
- for(it=adj[j].begin(); it!=adj[j].end(); it++)
- {
- if( *it==i)
- count++;
- }
- }
- cout<<"indegree "<<i<< ": "<< count<<endl;
- }
- }
- };
- int main()
- {
- graph g(7);
- g.add_adj(0, 2);
- g.add_adj(3, 2);
- g.add_adj(1, 3);
- g.add_adj(4, 2);
- g.add_adj(1, 5);
- g.add_adj(6, 5);
- g.add_adj(6,0);
- g.find_ind();
- return 0;
- }
Add Comment
Please, Sign In to add comment