TVec.Reverse Method

Overload List

#SignatureDescription
1TVec ReverseReverse vector elements.
└ indexed: TMtxVec Reverse(Int32 Index, Int32 Len)
2TVec Reverse(TMtxVec Vec)Reverse all Vec elements.
└ indexed: TMtxVec Reverse(TMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len)

Overload 1: TVec Reverse

Reverse vector elements.

Result: stored in self (calling object), returns self for chaining

Remarks:

The method reverses vector elements by using the following equation:

V[k]=Vec[Nk],0kN,where N=Vec.Length1\text{V}[k]=\text{Vec}[N-k],\quad 0\leq k \leq N, \quad \text{where } N=\text{Vec.Length}-1

This overload reverses all calling vector elements in-place.

Examples
Vector a = new Vector();
a.SetIt(new double[] { 1.0, 2.0, 3.0, 4.0 });
a.Reverse();
Vector expected = new Vector();
expected.SetIt(new double[] { 4.0, 3.0, 2.0, 1.0 });
if (!a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute))
    throw new Exception("Vector.Reverse: mismatch");
TVec a;
MtxVec.CreateIt(out a);
try
    {
        a.SetIt(false,new double[] {1,2,3,4});
        a.Reverse;   // a = new double[] {4,3,2,1}
    }
finally
    {
        MtxVec.FreeIt(ref a);
    }
See Also: TVec.Rotate, TVec.Shift

Indexed: TMtxVec Reverse(Int32 Index, Int32 Len)

Reverses the calling object elements [Index]..[Index+Len-1].

#NameTypeDescription
1IndexInt32start index
2LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

An exception is raised if array borders are overrun.

Overload 2: TVec Reverse(TMtxVec Vec)

Reverse all Vec elements.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx

Result: stored in self (calling object), returns self for chaining

Remarks:

Xtore the result in the calling vector elements. The Dew.Math.TMtxVecBase.Length and Dew.Math.TMtxVec.Complex roperties of the calling vector are set implicitly to match Vec vector.

Examples
Vector a = new Vector();
Vector x = new Vector();
x.SetIt(new double[] { 1.0, 2.0, 3.0, 4.0 });
a.Reverse(x);
Vector expected = new Vector();
expected.SetIt(new double[] { 4.0, 3.0, 2.0, 1.0 });
if (!a.IsEqual(expected, 1e-10, TCompare.cmpAbsolute))
    throw new Exception("Vector.Reverse: mismatch");

Indexed: TMtxVec Reverse(TMtxVec Vec, Int32 VecIndex, Int32 Index, Int32 Len)

Reverse vector elements.

#NameTypeDescription
1VecTMtxVecsource TVec or TMtx
2VecIndexInt32
3IndexInt32start index
4LenInt32element count

Result: stored in self (calling object), returns self for chaining

Remarks:

The method reverses Vec vector elements from [VecIndex].. [VecIndex+Len-1] and stores them in the calling vector from [Index]...[Index+Len-1] by using the following equation:

V[k]=Vec[Nk],0kN,where N=Vec.Length1\text{V}[k]=\text{Vec}[N-k],\quad 0\leq k \leq N, \quad \text{where } N=\text{Vec.Length}-1

This overload reverses calling vector elements in-place.

Examples
Vector a;
a.SetIt(false,new double[] {1,2,3,4});
a.Reverse;   // a = new double[] {4,3,2,1}