버블 정렬인데요 정렬이 제대로 안나와요ㅠ
비예
질문 제목 : 버블 정렬인데요 정렬이 제대로 안나와요ㅠ함수포인터를 이용한 버블정렬인데 틀린곳좀 고쳐주세요~~질문 내용 :
에러는 안나오는데...
정렬이 그대로 나와요ㅠㅠ
내림차순으로한거라 tom, jasmine, james, david, ashley 이렇게 나와야하는데 말이죠.....
아래 제 코드 붙입니다ㅠ#include iostream
#include stdio.h
#include string.h
using namespace std;
#define size 5
bool descend(char* name1, char* name2); // 내림차순
void bubblesort(char* name[], int size, bool descend(char*, char*));
void printall(char *name[], int size);
void swapname(char *x,char *y);
int main(void)
{
char* name[size] = {jasmine,ashley,tom,james,david};
cout 내림차순 버블정렬 전 : ;
printall(name,size);
bubblesort(name, size, descend);
cout 내림차순 버블정렬 후 : ;
printall(name, size);
return 0;
}
void bubblesort(char* name[], int size, bool descend(char*, char*))
{
int i,j;
for(i = 0; isize-1; i++)
{
for(j = 0; jsize-i-1; j++)
{
if(descend(name[j], name[j+1]))
swapname(name[j],name[j+1]);
}
}
}
bool descend(char* name1, char* name2)
{
if (name1 name2)
return 0;
else
return 1;
}
void swapname(char *x,char *y)
{
char *temp;
temp = x;
x = y;
y = temp;
}void printall(char *name[],int size)
{
int i;
for(i=0;isize;i++)
cout name[i] ;
cout endl;
}