Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int CSparseMatrix::getValue(int *coords)
- {
- bool found = false;
- int result = defaultValue;
- bool fit;
- for (int i = 0; i < valuesReallSize && !found; ++i)
- {
- fit = true;
- for (int j = 0; j < dimentionsQuantity && fit; ++j)
- {
- if ((*values[i]).coordinates[j] == coords[j])
- {
- if (j == dimentionsQuantity - 1)
- {
- found = true;
- result = (*values[i]).value;
- }
- }
- else
- {
- fit = false;
- }
- }
- }
- return result;
- }
- string CSparseMatrix::getString()
- {
- string result = "Matrix \"" + nameMatrix + "\" size: [";
- for (int dimension = 0; dimension < dimentionsQuantity; ++dimension)
- {
- result += to_string(dimentionsSizes[dimension]);
- if (dimension != dimentionsQuantity - 1)
- {
- result += ", ";
- }
- }
- result += "] values:";
- int *pointer = new int[dimentionsQuantity];
- for (int i = 0; i < dimentionsQuantity; ++i)
- {
- pointer[i] = 0;
- }
- bool end = false;
- bool found;
- result += valueString(pointer);
- while (!end)
- {
- found = false;
- for (int i = 0; i < dimentionsQuantity && !found; ++i)
- {
- if (pointer[i] == dimentionsSizes[i] - 1)
- {
- pointer[i] = 0;
- }
- else if (pointer[i] < dimentionsSizes[i])
- {
- pointer[i]++;
- found = true;
- i = 0;
- result += valueString(pointer);
- }
- if (i == dimentionsQuantity - 1 && !found)
- {
- end = true;
- }
- }
- }
- return result;
- }
- string CSparseMatrix::valueString(int *pointer)
- {
- string result = "";
- result += "[";
- int size = dimentionsQuantity;
- for (int j = 0; j < size; ++j)
- {
- result += to_string(pointer[j]);
- if (j < size - 1)
- {
- result += ", ";
- }
- }
- result += ("]: " + to_string(getValue(pointer)) + " ");
- return result;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement