Advertisement
J00ker

Untitled

Apr 29th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #define Nmax 1000
  4.  
  5. using namespace std;
  6.  
  7. struct Triplet
  8. {
  9. int i, j, v;
  10. };
  11.  
  12. struct Lista
  13. {
  14. Triplet t[Nmax];
  15. int pr, ul;
  16.  
  17. void Init()
  18. {
  19. pr = 0; ul = -1;
  20. }
  21.  
  22. int Empty()
  23. {
  24. return pr > ul;
  25. }
  26.  
  27. void InsertEnd(Triplet x)
  28. {
  29. t[++ul] = x;
  30. }
  31.  
  32. void Insert(int poz, Triplet x)
  33. {
  34. for(int i = ul; i >= poz + pr - 1; i--)
  35. t[i+1] = t[i];
  36. t[poz + pr - 1] = x;
  37. ul++;
  38. }
  39.  
  40. void Parcurgere()
  41. {
  42. if(Empty()) cout << "Lista este vida!";
  43. else
  44. {
  45. for(int i = pr; i <= ul; i++)
  46. cout << "(" << t[i].i << ", " << t[i].j << ", " << t[i].v << ")\n";
  47. cout << "\n";
  48. }
  49. }
  50.  
  51. void DeleteEnd()
  52. {
  53. if(!Empty()) ul--;
  54. }
  55.  
  56. void DeleteBegin()
  57. {
  58. if(!Empty()) pr++;
  59. }
  60.  
  61. void Delete(int poz)
  62. {
  63. if(Empty()) return;
  64. for(int i = poz + pr - 1; i < ul; i++)
  65. t[i] = t[i+1];
  66. ul--;
  67. }
  68.  
  69. Triplet GetElement(int k)
  70. {
  71. return t[pr + k - 1];
  72. }
  73.  
  74. /*
  75. int Search(Triplet x)
  76. {
  77. int i;
  78. for(i = pr; i <= ul; i++)
  79. if(t[i] == x) return i - pr + 1;
  80. return -1;
  81. }
  82. */
  83.  
  84. int Size()
  85. {
  86. return ul - pr + 1;
  87. }
  88.  
  89. };
  90.  
  91. int a[Nmax][Nmax], n;
  92.  
  93. int main()
  94. {
  95. ifstream fin("matrice.in");
  96. fin >> n;
  97. for(int i = 0; i < n; i++)
  98. for(int j = 0; j < n; j++)
  99. fin >> a[i][j];
  100. fin.close();
  101.  
  102. Lista L;
  103. L.Init();
  104. Triplet aux;
  105. for(int i = 0; i < n; i++)
  106. for(int j = 0; j < n; j++)
  107. {
  108. if(a[i][j] != 0)
  109. {
  110. aux.i = i;
  111. aux.j = j;
  112. aux.v = a[i][j];
  113. L.InsertEnd(aux);
  114. }
  115.  
  116. }
  117. cout << "-i--j--v-\n";
  118. L.Parcurgere();
  119.  
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement