Ejemplo n.º 1
0
        public void SetElem(long lineNumber, int colNumber, int index, T elem)
        {
            if (index < 0)
            {
                throw new System.IndexOutOfRangeException(
                          (lineNumber.ToString() + ", " + colNumber.ToString() + " OutOfRange exception: illegal index"));
            }
            if (index >= N)
            {
                throw new System.IndexOutOfRangeException(
                          (lineNumber.ToString() + ", " + colNumber.ToString() + " OutOfRange exception: illegal index"));
            }

            int i = JA.IndexOf(index);

            if (i != -1)
            {
                if (!isZero(elem))
                {
                    AN[i] = elem;
                }
                else
                {
                    for (int j = i; j < curCountOfElems - 1; j++)
                    {
                        AN[j] = AN[j + 1];
                        JA[j] = JA[j + 1];
                    }
                    JA[--curCountOfElems] = -1;
                }
            }
            else
            {
                if (!isZero(elem))
                {
                    if (curCountOfElems == AN.Count)
                    {
                        AN.Add(elem);
                        JA.Add(-1);
                    }

                    AN[curCountOfElems] = elem;
                    JA[curCountOfElems] = index;
                    curCountOfElems++;
                }
            }
        }
Ejemplo n.º 2
0
        public void SetElem(long lineNumber, int colNumber, int index1, int index2, T elem)
        {
            if ((index1 < 0) || (index2 < 0))
            {
                throw new System.IndexOutOfRangeException(
                          (lineNumber.ToString() + ", " + colNumber.ToString() + " OutOfRange exception: illegal index"));
            }
            if ((index1 >= M) || (index2 >= N))
            {
                throw new System.IndexOutOfRangeException(
                          (lineNumber.ToString() + ", " + colNumber.ToString() + " OutOfRange exception: illegal index"));
            }

            int j;

            for (j = IA[index1]; j < IA[index1 + 1]; j++)
            {
                if (JA[j] == index2)
                {
                    break;
                }
            }
            if (j < IA[index1 + 1])
            {
                if (!isZero(elem))
                {
                    AN[j] = elem;
                }
                else
                {
                    for (int k = j; k < curCountOfElems - 1; k++)
                    {
                        AN[k] = AN[k + 1];
                        JA[k] = JA[k + 1];
                    }
                    JA[--curCountOfElems] = -1;
                    for (int k = index1; k < IA.Length; k++)
                    {
                        IA[k] -= 1;
                    }
                    IA[0] = 0;
                }
            }
            else
            {
                if (!isZero(elem))
                {
                    if (curCountOfElems == AN.Count)
                    {
                        AN.Add(elem);
                        JA.Add(-1);
                    }

                    for (int k = index1 + 1; k < IA.Length; k++)
                    {
                        IA[k] += 1;
                    }
                    for (int k = curCountOfElems - 1; k >= IA[index1 + 1] - 1; k--)
                    {
                        AN[k + 1] = AN[k];
                        JA[k + 1] = JA[k];
                    }
                    AN[IA[index1 + 1] - 1] = elem;
                    JA[IA[index1 + 1] - 1] = index2;
                    curCountOfElems++;
                }
            }
        }