나는 포인터를 교환하여 문자 포인터의 배열 (문자 * _string를) 정렬 할 노력하고 있어요.스와핑 포인터로 문자 배열을 정렬, C++
나는이 메소드를 가지고 있는데, _string에서 가져온 값을 사용하고 _string을 조작하지 않고 정렬하지만 빈 헬퍼 배열 (char * _output)은 메소드로 넘겨 준다.
사람이 나를 도와 내가 뭘 잘못 말해 줄래? 내가 출력 배열이 정렬 된 값을 포함하려면, 그 코드 후
char * string = {"bcdae"};
char * output = new char[5];
sortAsc(string, output);
: 내 주요-방법에
void sortAsc(char* _string, char* _output)
{
int length = strlen(_string);
// output and string now point to the same area in the memory
_output = _string;
for(int i = 0; i < length; i++) {
for(int j = 0; j < length; j++) {
if(*(_output) > (_output[j])) {
// save the pointer
char* tmp = _output;
// now output points to the smaller value
_output = _output+j;
// move up the pointer to the smaller value
_output + j;
// now the pointer of the smaller value points to the higher value
_output = tmp;
// move down to where we were + 1
_output - j + 1;
}
}
}
//_output[length]='\0';
//delete chars;
}
, 내가 이런 일을한다.
? 받고있는 샘플 입력 및 출력 또는 오류를 제공하십시오. 후 –
는'_output = _string' 당신이 함수에 전달 된 도우미 배열에 대한 참조를 잃게됩니다, 확실히이 도움이되지 않습니다. – Jack
출력 변수를 컴파일 한 후 "abcde"여야합니다. 이 시점에서, 프로그램은 오류가 발생하지 않지만, 출력 변수는 메소드를 호출 한 후 단순히 여전히 비어 있습니다. –