Quote:
Originally Posted by Programmer
Zzz...
PHP Code:
function onCreated() { temp.dataSet = {1, 6, 4, 2, 5, 8, 20, 100, 54, 1000, 523}; echo(temp.dataSet); temp.dataSet = selectionSort(temp.dataSet); echo(temp.dataSet); temp.dataSet = null; temp.dataSet.destroy(); }
function selectionSort(temp.data) { for (a = 0; a < temp.data.size() - 1; a++) { for (b = a + 1; b < temp.data.size(); b++) { if (temp.data[b] < temp.data[a]) { result = temp.data[b]; temp.data[b] = temp.data[a]; temp.data[a] = result; } } } return temp.data; }
|
That would cause an error because temp.dataSet is not an object with a destroy() function. And temp variables are destroyed automatically anyways when the function is over, no need to set it to null. Also, function parameters are automatically temp, you don't need to specify it. It's also less costly to send the array by reference using temp.dataSet.link() rather than duplicating it.
PHP Code:
function onCreated() {
temp.dataset = {1, 6, 4, 2, 5, 8, 20, 100, 54, 1000, 523};
echo(dataset);
this.selectionsort(dataset.link());
echo(dataset);
}
function selectionsort(data) {
temp.a = 0;
temp.b = 0;
temp.tmp = 0;
for (a = 0; a < data.size() - 1; a++) {
for (b = a + 1; b < data.size(); b++) {
if (data[b] < data[a]) {
tmp = data[b];
data[b] = data[a];
data[a] = tmp;
}
}
}
}
Once a temp variable is initialized it can be referenced without using the temp prefix, however using the prefix is marginally faster.
Python is superior though.
