Advertisement
HmHimu

list with degree 245

May 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. #include<iostream>
  2. #include<list>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. list<int> adj[100];
  8. list<int>::iterator it;
  9.  
  10. int v,i,j,a,b,k=1;
  11.  
  12. cout<<"vertex: ";
  13. cin>>v;
  14.  
  15. do{
  16.  
  17. cout<<"Edge"<<k<<":";
  18. cin>> a >> b ;
  19. cout<<endl;
  20.  
  21. if(a>v+1 || b>v+1)
  22. {
  23. cout<<"Input is invalid"<<endl;
  24.  
  25. }
  26. else{
  27.  
  28. adj[a].push_back(b);
  29.  
  30. adj[b].push_back(a);
  31. }
  32. k++;
  33.  
  34. }while(a!=0 && b!=0);
  35.  
  36.  
  37.  
  38.  
  39. for(i=1;i<=v;i++){
  40. cout<<"adj[" << i<<"]";
  41. int count=0;
  42. for(it=adj[i].begin();it!=adj[i].end();it++)
  43. {
  44. cout<<"->"<<*it;
  45. count++;
  46.  
  47. }
  48.  
  49. cout<<"degree of"<< i<<"is"<<count;
  50. cout<<endl;
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement