<HTML>
</head>
<script>
function biDirectional(arrayName,length)
{
if(var i < (length-1))
{
if(var j < length)
{
for(i=0; i<=(length-1);i++)
{
for(j=i+1; j<=length; j++)
{
if(arrayName[j] <arrayName[i])
{
var dummy=arrayName[i];
arrayName[i]=arrayName[j]
arrayName[j]=dummy;
}
}
}
}
}
if(i = (length-1))
{
if(j = length)
{
for(i=(length-1); i>=0;i--)
{
for(j=(length); j>=1; j--)
{
if(arrayName[j] <arrayName[i])
{
var dummy=arrayName[i];
arrayName[i]=arrayName[j]
arrayName[j]=dummy;
}
}
}
}
}
}
var myArray= new Array(5,2,7,9,1);
var myArrayLength=5;
document.write('Unsorted: ',myArray);
myBubbleSort(myArray,myArrayLength);
document.write('------------>Sorted: ',myArray);
</script>
</head>
</HTML>
i tried to make a bidirectional bubblesort by myself and this is what i got.
it says that there is a syntax error on the line with the code:
if(var i < (length-1))
but i really dont know why
is it really a syntax error, or does this code simply not work??
please help!!

New Topic/Question
Reply



MultiQuote




|