Advertisement
Guest User

Alocare_statica-dinamica_STUNT3R.cpp

a guest
Nov 26th, 2015
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. /*
  2.  
  3. */
  4. #include <iostream>
  5. #include <fstream>
  6. #include <cmath>
  7. using namespace std;
  8. ifstream fin("date.in");
  9. struct nod
  10. {
  11. int nr;
  12. nod *next;
  13. } *l[20];
  14. int n,m, t[2][20],start[20],k;
  15. void citire()
  16. {
  17. fin>>n>>m;
  18. int x,y;
  19. while(fin>>x>>y)
  20. {
  21. k++;
  22. t[0][k]=y;
  23. t[1][k]=start[x];
  24. start[x]=k;
  25. k++;
  26. t[0][k]=x;
  27. t[1][k]=start[y];
  28. start[y]=k;
  29. }
  30. }
  31. void construire()
  32. {
  33. nod *p;
  34. for(int i=1;i<=n;i++)
  35. {
  36. int x=start[i];
  37. while(x)
  38. {
  39. p=new nod;
  40. p->nr=t[0][x];
  41. p->next=l[i];
  42. l[i]=p;
  43. x=t[1][x];
  44. }
  45. }
  46. }
  47. void afisare()
  48. {
  49. /* for(int i=1;i<=n;i++)
  50. {
  51. int x=start[i];
  52. cout<<"\nLista nodului "<<i<<" : ";
  53. while(x)
  54. {
  55. cout<<t[0][x]<<" ";
  56. x=t[1][x];
  57.  
  58. }
  59. cout<<endl;
  60. }
  61. */
  62. for(int i=1;i<=n;i++)
  63. {
  64. nod *x;
  65. x=l[i];
  66. cout<<"\nLista nodului "<<i<<" : ";
  67. while(x)
  68. {
  69. cout<<x->nr<<" ";
  70. x=x->next;
  71. }
  72. }
  73. }
  74. int main()
  75. {
  76. citire();
  77. construire();
  78. afisare();
  79.  
  80. return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement