Dev-C++를 사용합니다. 정렬 기능을 사용할 때마다 프로그램이 중단됩니다.정렬 - 버블/선택
#include<iostream>
#include<string.h>
using namespace std;
void bsort(char * items,int length)
{
bool ex = true;
for(int a = 0;a < length;a++)
{
cout<<"Exchange";
if(ex == false) break;
ex = false;
for(int b = 0;b >= (length-1);b++)
{
if(items[b] < items[b+1])
{
ex = true;
items[b] ^= items[b+1];
items[b+1] ^= items[b];
items[b] ^= items[b+1];
}
}
}
cout<<items;
}
void sort(char * items,int count)
{
register int a,b;
register char t;
for(a = 1;a < count;++a)
{
for(b = count-1; b >= a;--b)
{
if(items[b-1] > items[b])
{
cout<<"Exchange";
t = items[b-1];
items[b-1] = items[b];
items[b] = t;
}
}
}
}
void xselect(char * items,int count)
{
char c = items[0];
for(int a = 1;a < count;a++)
{
if(c > items[a])
{
c ^= items[a];
items[a] ^= c;
c ^= items[a];
}
}
cout<<items;
}
int main()
{
char * p = "I am awesome";
xselect(p,strlen(p));
cout<<p;
return cin.get();
}
어떤 문제가 있습니까?
char * p = "I am awesome";
:
편집 : 당신이 당신의 기능에
나는 당신의 중첩 루프에서 조건이 잘못 생각합니다. – 0x499602D2
왜 'register' 변수를 사용하고 있습니까? – 0x499602D2
왜 xor를 스와핑에 사용합니까? 대부분의 경우 그것은 관용적 인 임시 변수를 사용하는 것보다 느리고, 어쨌든 더 모호합니다. – MatthiasB