[CPP]#include "stdafx.h"
#include <iostream>
#include <cstdlib>
using namespace std;
void Bubble(int* anArray, int arraySize)
{
int i = 0;
int j = 0;
int temp;
for(i=0; i< (arraySize - 1); ++i)
{
for(j = i + 1; j > 0; --j)
{
if(anArray[j] < anArray[j-1])
{
//Swaps the values
temp = anArray[j];
anArray[j] = anArray[j - 1];
anArray[j - 1] = temp;
}
}
}
cout << anArray[0] << anArray[1];
}
int _tmain(int argc, _TCHAR* argv[])
{
int B[2] = {0,1};
Bubble(B,2);
system("PAUSE");
return 0;
}[/CPP]
De output is echter gewoon '01', hij swapt dus helemaal niet terwijl het logaritme volgens mij wel goed is.
Er zal dus wel iets fout zijn met verwijzingen, maar ik zie niet wat.
Alvast bedankt!
Groeten
#include <iostream>
#include <cstdlib>
using namespace std;
void Bubble(int* anArray, int arraySize)
{
int i = 0;
int j = 0;
int temp;
for(i=0; i< (arraySize - 1); ++i)
{
for(j = i + 1; j > 0; --j)
{
if(anArray[j] < anArray[j-1])
{
//Swaps the values
temp = anArray[j];
anArray[j] = anArray[j - 1];
anArray[j - 1] = temp;
}
}
}
cout << anArray[0] << anArray[1];
}
int _tmain(int argc, _TCHAR* argv[])
{
int B[2] = {0,1};
Bubble(B,2);
system("PAUSE");
return 0;
}[/CPP]
De output is echter gewoon '01', hij swapt dus helemaal niet terwijl het logaritme volgens mij wel goed is.
Er zal dus wel iets fout zijn met verwijzingen, maar ik zie niet wat.
Alvast bedankt!
Groeten