struct Int
{
int n;
bool check;
};
void BubbleSort(vector<Int> arr)
{
int swapCount = 0;
int compareCount = 0;
vector<int> minusIdx;
for (int i = 0; i < arr.size(); i++)
{
for (int j = arr.size() - 1; j > i; j--)
{
if (arr[j-1].n > arr[j].n)
{
swap(arr[j-1], arr[j]);
//arr[i].check = true;
arr[j].check = true;
swapCount++;
}
compareCount++;
}
cout << endl << "비교 횟수 : " << compareCount << endl;
cout << endl << "교환 횟수 : " << swapCount << endl;
}
for (int i = 0; i < arr.size(); i++)
{
if (arr[i].check == false)
arr[i].n *= -1;
printf("%d ", arr[i].n);
}
}
int main(void)
{
vector<Int> arr = { {6,false}, {4,false},{3,false},{7,false},{1,false},{9,false},{8,false} };
BubbleSort(arr);
return 0;
}