help me ....the problems with array



i wanna delete something which the value bigger than the other by me given in the array,,then output the array, but the result of don't change. i dunno the code wrong with which step ....sos look at following code


/********************************************************************/
#include <iostream>

#include <iomanip>

bool _Judge_Lager(int _a,int _b)

{

return _a>_b?true:false;

}

namespace ystdex
{

template<typename Forwarditerator,class _condiation,typename _Intergal_value>

Forwarditerator _Remove_If(Forwarditerator& _First,Forwarditerator& _End,const _condiation pred,const _Intergal_value & _A)

{

Forwarditerator& _reslut=_First;

while (_First!=_End)
{

if (!pred(*_First,_A))
{

*_reslut=*_First;

}

++_First;

++_reslut;
}

return _reslut;
}

}

template<class _Intergal_Type,std::size_t _Dimensional>

constexpr std::size_t _arrlen(const _Intergal_Type (&_arr)[_Dimensional])

{

return _Dimensional;

}

int main(int agrc,char*agrv[])

{
int _Mycontainers[]={1,2,3,4,5,6,7,8};

int _check_value=4;

int *_Int_Begin=_Mycontainers;

int *_Int_End=_Mycontainers+_arrlen(_Mycontainers);

_Int_End=ystdex::_Remove_If(_Int_Begin, _Int_End, _Judge_Lager, _check_value);

for (auto _Ergodic:_Mycontainers)
{

std::cout<<_Ergodic<<std::setw(4);

}

return 0;
}
Your algorithm _Remove_If is written incorrectly. You defined iterator _reslut as reference to iterator First. So they point to the same element in the sequence.

Forwarditerator& _reslut=_First;

You should define it as a copy of the initial state of the iterator First that is without reference

Forwarditerator_reslut=_First;

Also the increment of result you should include into the if statement. So instead of

if (!pred(*_First,_A))
{

*_reslut=*_First;

}

++_First;

++_reslut;

the following must be

if (!pred(*_First,_A))
{

*_reslut=*_First;
++_reslut;
}

++_First;

,,.......i'm following the method which was provided by 2L.........but out of work all.....
Show your updated code. Take into account that you can not delete elements of an array. You can only move them at the end of the array that your algorithm is trying to do.
Topic archived. No new replies allowed.