|
-
Dec 17th, 2003, 03:08 AM
#1
Good sorting in JavaScript
Does anyone know of a free JavaScript implementation of a fast sorting algorithm? MergeSort, Quicksort, any of those.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 17th, 2003, 12:25 PM
#2
Frenzied Member
Is Bubble sort too slow?
You could make it go through one item less each time, this would speed it up a bit.
eg, first it checks all 10 items, then the 9 first, the 8, 7 etc...
That speeds it up a bit.
Have I helped you? Please Rate my posts. 
-
Dec 17th, 2003, 04:28 PM
#3
Bubble sort is too slow. I need a n*logn approach, not a n² approach.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 17th, 2003, 04:38 PM
#4
Frenzied Member
I found this:
http://www.concentric.net/~ttwang/sort/quick.c
Which is supposedly quite quick. I cannot read Java so I can't convert it to JavaScript though.
Will keep looking.
edit:
http://cg.scs.carleton.ca/~morin/misc/sortalg/
gives lots of algorithms, MergeSort seems the best.
Last edited by Acidic; Dec 17th, 2003 at 04:51 PM.
Have I helped you? Please Rate my posts. 
-
Dec 17th, 2003, 04:51 PM
#5
Thanks, but
1) It's C, not Java (not that that matters, I can read both).
2) I can find source in other languages easily, it's JavaScript that poses a problem
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 17th, 2003, 04:52 PM
#6
Frenzied Member
well, give me the psuedo code and I'll do it.
Have I helped you? Please Rate my posts. 
-
Dec 17th, 2003, 04:54 PM
#7
Found one
Code:
function quickSort(arrTable, intColumn, sp, zg) {
var k = arrTable[Math.round((sp+zg)/2)][intColumn];
var i = sp;
var j = zg;
while (j > i) {
while (arrTable[i][intColumn] < k)
++i;
while (k < arrTable[j][intColumn])
j = j - 1;
if (i <= j) {
var d = arrTable[i];
arrTable[i] = arrTable[j];
arrTable[j] = d;
++i;
j = j - 1;
}
}
if (sp<j)
quickSort(arrTable, intColumn, sp, j);
if (i<zg)
quickSort(arrTable, intColumn, i, zg);
}
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Dec 17th, 2003, 04:58 PM
#8
Frenzied Member
I presume that arrTable is the table you want sorted, but what are:intColumn, sp and zg?
Have I helped you? Please Rate my posts. 
-
Dec 17th, 2003, 05:03 PM
#9
intColumn is because this function can sort multidim arrays, sp and zg are sort internals.
I have to rewrite it for DOM nodes anyway...
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|