Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. int CSparseMatrix::getValue(int *coords)
  2. {
  3.     bool found = false;
  4.     int result = defaultValue;
  5.     bool fit;
  6.     for (int i = 0; i < valuesReallSize && !found; ++i)
  7.     {
  8.         fit = true;
  9.         for (int j = 0; j < dimentionsQuantity && fit; ++j)
  10.         {
  11.             if ((*values[i]).coordinates[j] == coords[j])
  12.             {
  13.                 if (j == dimentionsQuantity - 1)
  14.                 {
  15.                     found = true;
  16.                     result = (*values[i]).value;
  17.                 }
  18.             }
  19.             else
  20.             {
  21.                 fit = false;
  22.             }
  23.         }
  24.     }
  25.     return result;
  26. }
  27.  
  28. string CSparseMatrix::getString()
  29. {
  30.     string result = "Matrix \"" + nameMatrix + "\" size: [";
  31.  
  32.     for (int dimension = 0; dimension < dimentionsQuantity; ++dimension)
  33.     {
  34.         result += to_string(dimentionsSizes[dimension]);
  35.         if (dimension != dimentionsQuantity - 1)
  36.         {
  37.             result += ", ";
  38.         }
  39.     }
  40.  
  41.     result += "] values:";
  42.     int *pointer = new int[dimentionsQuantity];
  43.     for (int i = 0; i < dimentionsQuantity; ++i)
  44.     {
  45.         pointer[i] = 0;
  46.     }
  47.  
  48.     bool end = false;
  49.     bool found;
  50.  
  51.     result += valueString(pointer);
  52.  
  53.     while (!end)
  54.     {
  55.         found = false;
  56.         for (int i = 0; i < dimentionsQuantity && !found; ++i)
  57.         {
  58.             if (pointer[i] == dimentionsSizes[i] - 1)
  59.             {
  60.                 pointer[i] = 0;
  61.             }
  62.             else if (pointer[i] < dimentionsSizes[i])
  63.             {
  64.  
  65.                 pointer[i]++;
  66.                 found = true;
  67.                 i = 0;
  68.  
  69.                 result += valueString(pointer);
  70.             }
  71.             if (i == dimentionsQuantity - 1 && !found)
  72.             {
  73.                 end = true;
  74.             }
  75.         }
  76.     }
  77.     return result;
  78. }
  79.  
  80. string CSparseMatrix::valueString(int *pointer)
  81. {
  82.     string result = "";
  83.     result += "[";
  84.     int size = dimentionsQuantity;
  85.     for (int j = 0; j < size; ++j)
  86.     {
  87.         result += to_string(pointer[j]);
  88.         if (j < size - 1)
  89.         {
  90.             result += ", ";
  91.         }
  92.     }
  93.     result += ("]: " + to_string(getValue(pointer)) + " ");
  94.  
  95.     return result;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement