Vector::Reverse Method

Overload List

#SignatureDescription
1TMtxVec *Reverse(TMtxVec *Vec, int VecIndex, int Index, int Len) const;Reverse vector elements.
2TMtxVec *Reverse(int Index, int Len) const;Reverses the calling object elements [Index]..[Index+Len-1].
3TVec *Reverse() const;Reverse vector elements.
4TVec *Reverse(TMtxVec *Vec) const;Reverse all Vec elements.

Overload 1: TMtxVec *Reverse(TMtxVec *Vec, int VecIndex, int Index, int Len) const;

Reverse vector elements.

#NameTypeDescription
1VecTMtxVec *
2VecIndexint
3Indexint
4Lenint
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[N−k],0≤k≤N,where N=Vec.Length−1\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
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Vector a;

    a.SetIt(false, DewArray<double>{1, 2, 3, 4});
    a.Reverse(); // a = [4,3,2,1]
}
See Also: Vector::Rotate, Vector::Shift
Declared in Dew::Math::Vector · Dew.Math/MtxExpr.h · Cross-compiler

Overload 2: TMtxVec *Reverse(int Index, int Len) const;

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

#NameTypeDescription
1Indexint
2Lenint
Remarks:

An exception is raised if array borders are overrun.

Examples
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Vector a;

    a = {1, 2, 3, 4};
    a.Reverse(); // a = [4,3,2,1]
}
Declared in Dew::Math::Vector · Dew.Math/MtxExpr.h · Cross-compiler

Overload 3: TVec *Reverse() const;

Reverse vector elements.

Remarks:

The method reverses vector elements by using the following equation:

V[k]=Vec[N−k],0≤k≤N,where N=Vec.Length−1\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
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Vector a;
    a.SetIt(DewArray<double>{ 1.0, 2.0, 3.0, 4.0 });
    a.Reverse();
    Vector expected;
    expected.SetIt(DewArray<double>{ 4.0, 3.0, 2.0, 1.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Vector.Reverse: mismatch");
}
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Vector a;

    a.SetIt(false, DewArray<double>{1, 2, 3, 4});
    a.Reverse(); // a = [4,3,2,1]
}
See Also: Vector::Rotate, Vector::Shift
Declared in Dew::Math::Vector · Dew.Math/MtxExpr.h · Cross-compiler

Overload 4: TVec *Reverse(TMtxVec *Vec) const;

Reverse all Vec elements.

#NameTypeDescription
1VecTMtxVec *
Remarks:

Store the result in the calling vector elements. The Vector::Length and Vector::Complex properties of the calling vector are set implicitly to match Vec vector.

Examples
#include "Math387.h"
#include "MtxExpr.h"

using namespace Dew;
using namespace Dew::Math;

void Example()
{
    Vector a;
    Vector x;
    x.SetIt(DewArray<double>{ 1.0, 2.0, 3.0, 4.0 });
    a.Reverse(x);
    Vector expected;
    expected.SetIt(DewArray<double>{ 4.0, 3.0, 2.0, 1.0 });
    if (!a.IsEqual(expected, 1e-10, TCompare::cmpAbsolute))
        throw tException("Vector.Reverse: mismatch");
}
Declared in Dew::Math::Vector · Dew.Math/MtxExpr.h · Cross-compiler