[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

JT

3/4/2016 10:00:00 AM

I was thinking sorting links for each node, using a simple bubblesort, it is not that many links on each node usually. A link can't be equal to another so no "=" needed.
arr[i] contain the nodes and nodelinks[] is an array of links 1,4,2,3,0 for example.

Does it seem in principal right?

// Sort links
function sortlinks()
{

for(var i = 0; i < nodes; nodes ++ )
{
sorted = false;
while(sorted==false)
{
sorted=true;
for (var j=0;j<arr[i].nodelinks.length;j++){
if (arr[i].nodelinks[j] > arr[i].nodelinks[j + 1])
{
temp = arr[i].nodelinks[j];
arr[i].nodelinks[j] = arr[i].nodelinks[j + 1];
arr[i].nodelinks[j + 1] = temp;
sorted = false;
}
}

}
}

}
41 Answers

Man-wai Chang ToDie

3/4/2016 10:53:00 AM

0

On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
> I was thinking sorting links for each node, using a simple bubblesort, it is not that many links on each node usually. A link can't be equal to another so no "=" needed.
> arr[i] contain the nodes and nodelinks[] is an array of links 1,4,2,3,0 for example.
>
> Does it seem in principal right?

Does Javascript have a function to sort arrays?

--
@~@ Remain silent. Nothing from soldiers and magicians is real!
/ v \ Simplicity is Beauty! May the Force and farces be with you!
/( _ )\ (Fedora release 23) Linux 4.4.3-300.fc23.x86_64
^ ^ 18:42:01 up 16:51 0 users load average: 1.04 1.04 1.05
不å??貸! 不詐é¨?! 不援交! 不æ??交! 不æ??å?«! 不è?ªæ®º! è«?è??æ?®ç¶?援 (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_...

Evertjan.

3/4/2016 11:02:00 AM

0

"Mr. Man-wai Chang" <toylet.toylet@gmail.com> wrote on 04 Mar 2016 in
comp.lang.javascript:

> On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
>> I was thinking sorting links for each node, using a simple bubblesort,
>> it is not that many links on each node usually. A link can't be equal
>> to another so no "=" needed. arr[i] contain the nodes and nodelinks[]
>> is an array of links 1,4,2,3,0 for example.
>>
>> Does it seem in principal right?
>
> Does Javascript have a function to sort arrays?

If the array is just sorted numerical or string-wize hexadecimal:
<http://www.w3schools.com/jsref/jsref_so...

Javascript has a fine sort function that can call a compare function,
the called function can compare whatever you like.

So bubble-sort, while a nice exercise for newbies, is probably much slower.


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

JT

3/4/2016 11:03:00 AM

0

Den fredag 4 mars 2016 kl. 12:01:28 UTC+1 skrev Evertjan.:
> "Mr. Man-wai Chang" <toylet.toylet@gmail.com> wrote on 04 Mar 2016 in
> comp.lang.javascript:
>
> > On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
> >> I was thinking sorting links for each node, using a simple bubblesort,
> >> it is not that many links on each node usually. A link can't be equal
> >> to another so no "=" needed. arr[i] contain the nodes and nodelinks[]
> >> is an array of links 1,4,2,3,0 for example.
> >>
> >> Does it seem in principal right?
> >
> > Does Javascript have a function to sort arrays?
>
> If the array is just sorted numerical or string-wize hexadecimal:
> <http://www.w3schools.com/jsref/jsref_so...
>
> Javascript has a fine sort function that can call a compare function,
> the called function can compare whatever you like.
>
> So bubble-sort, while a nice exercise for newbies, is probably much slower.
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

Thank's Evertjan.

JT

3/4/2016 11:05:00 AM

0

Den fredag 4 mars 2016 kl. 11:53:32 UTC+1 skrev Mr. Man-wai Chang:
> On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
> > I was thinking sorting links for each node, using a simple bubblesort, it is not that many links on each node usually. A link can't be equal to another so no "=" needed.
> > arr[i] contain the nodes and nodelinks[] is an array of links 1,4,2,3,0 for example.
> >
> > Does it seem in principal right?
>
> Does Javascript have a function to sort arrays?
>
> --
> @~@ Remain silent. Nothing from soldiers and magicians is real!
> / v \ Simplicity is Beauty! May the Force and farces be with you!
> /( _ )\ (Fedora release 23) Linux 4.4.3-300.fc23.x86_64
> ^ ^ 18:42:01 up 16:51 0 users load average: 1.04 1.04 1.05
> ???! ???! ???! ???! ???! ???! ????? (CSSA):
> http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_...

Thank's Man-wai Chang

JT

3/4/2016 11:56:00 AM

0

Den fredag 4 mars 2016 kl. 12:04:45 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 4 mars 2016 kl. 11:53:32 UTC+1 skrev Mr. Man-wai Chang:
> > On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
> > > I was thinking sorting links for each node, using a simple bubblesort, it is not that many links on each node usually. A link can't be equal to another so no "=" needed.
> > > arr[i] contain the nodes and nodelinks[] is an array of links 1,4,2,3,0 for example.
> > >
> > > Does it seem in principal right?
> >
> > Does Javascript have a function to sort arrays?
> >
> > --
> > @~@ Remain silent. Nothing from soldiers and magicians is real!
> > / v \ Simplicity is Beauty! May the Force and farces be with you!
> > /( _ )\ (Fedora release 23) Linux 4.4.3-300.fc23.x86_64
> > ^ ^ 18:42:01 up 16:51 0 users load average: 1.04 1.04 1.05
> > ???! ???! ???! ???! ???! ???! ????? (CSSA):
> > http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_...
>
> Thank's Man-wai Chang

I thought that this would do it but id doesn't sort the subobject/attribute array nodelinks. This is written out after call to arr[i].nodelinks.sort();
nodelinks is an array within the arr object/array.

1,10,11,12,13,14,15,16,17,2,3,4,5,6,7,8,9

// Sort links
function sortlinks()
{
for(var i = 0; i < nodes; nodes ++ )
{
arr[i].nodelinks.sort();
document.write(arr[i].nodelinks);p.stop();
}
}

JT

3/4/2016 1:16:00 PM

0

Den fredag 4 mars 2016 kl. 12:01:28 UTC+1 skrev Evertjan.:
> "Mr. Man-wai Chang" <toylet.toylet@gmail.com> wrote on 04 Mar 2016 in
> comp.lang.javascript:
>
> > On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
> >> I was thinking sorting links for each node, using a simple bubblesort,
> >> it is not that many links on each node usually. A link can't be equal
> >> to another so no "=" needed. arr[i] contain the nodes and nodelinks[]
> >> is an array of links 1,4,2,3,0 for example.
> >>
> >> Does it seem in principal right?
> >
> > Does Javascript have a function to sort arrays?
>
> If the array is just sorted numerical or string-wize hexadecimal:
> <http://www.w3schools.com/jsref/jsref_so...
>
> Javascript has a fine sort function that can call a compare function,
> the called function can compare whatever you like.
>
> So bubble-sort, while a nice exercise for newbies, is probably much slower.
>
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

I thought this would sort the property "subarray" nodelinks.

arr[0].nodelinks.sort();

But after sort it write out same content as before sort.
1,10,11,12,13,14,15,16,17,2,3,4,5,6,7,8,9

My object something like this.

arr[k] ={nodelinks : []};

JT

3/4/2016 1:42:00 PM

0

Den fredag 4 mars 2016 kl. 14:15:50 UTC+1 skrev jonas.t...@gmail.com:
> Den fredag 4 mars 2016 kl. 12:01:28 UTC+1 skrev Evertjan.:
> > "Mr. Man-wai Chang" <toylet.toylet@gmail.com> wrote on 04 Mar 2016 in
> > comp.lang.javascript:
> >
> > > On 3/4/2016 6:00 PM, jonas.thornvall@gmail.com wrote:
> > >> I was thinking sorting links for each node, using a simple bubblesort,
> > >> it is not that many links on each node usually. A link can't be equal
> > >> to another so no "=" needed. arr[i] contain the nodes and nodelinks[]
> > >> is an array of links 1,4,2,3,0 for example.
> > >>
> > >> Does it seem in principal right?
> > >
> > > Does Javascript have a function to sort arrays?
> >
> > If the array is just sorted numerical or string-wize hexadecimal:
> > <http://www.w3schools.com/jsref/jsref_so...
> >
> > Javascript has a fine sort function that can call a compare function,
> > the called function can compare whatever you like.
> >
> > So bubble-sort, while a nice exercise for newbies, is probably much slower.
> >
> >
> > --
> > Evertjan.
> > The Netherlands.
> > (Please change the x'es to dots in my emailaddress)
>
> I thought this would sort the property "subarray" nodelinks.
>
> arr[0].nodelinks.sort();
>
> But after sort it write out same content as before sort.
> 1,10,11,12,13,14,15,16,17,2,3,4,5,6,7,8,9
>
> My object something like this.
>
> arr[k] ={nodelinks : []};

I can not find any examples for howto sort an array that is a property of another array.

So if anyone or you Evertjan have the time so show me, i would be greatful.
I realise it can not be that hard, but i thought my attempt made sense, evidently it didn't. So how do i reach the array and sort it.

Man-wai Chang ToDie

3/4/2016 1:55:00 PM

0

On 3/4/2016 7:01 PM, Evertjan. wrote:
>
> So bubble-sort, while a nice exercise for newbies, is probably much slower.
>

There are books on sorting algorithms, with maths to compare their
efficiency. Well, I seldom need to reinvent the wheels. :)

--
@~@ Remain silent. Nothing from soldiers and magicians is real!
/ v \ Simplicity is Beauty! May the Force and farces be with you!
/( _ )\ (Fedora release 23) Linux 4.4.3-300.fc23.x86_64
^ ^ 21:42:01 up 19:51 0 users load average: 1.05 1.03 1.05
不å??貸! 不詐é¨?! 不援交! 不æ??交! 不æ??å?«! 不è?ªæ®º! è«?è??æ?®ç¶?援 (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_...

Man-wai Chang ToDie

3/4/2016 1:57:00 PM

0

On 3/4/2016 9:41 PM, jonas.thornvall@gmail.com wrote:
>
> I can not find any examples for howto sort an array that is a property of another array.
>
> So if anyone or you Evertjan have the time so show me, i would be greatful.

Can you flatten the tree into a linear array, sort it, then rebuild the
tree?

--
@~@ Remain silent. Nothing from soldiers and magicians is real!
/ v \ Simplicity is Beauty! May the Force and farces be with you!
/( _ )\ (Fedora release 23) Linux 4.4.3-300.fc23.x86_64
^ ^ 21:42:01 up 19:51 0 users load average: 1.05 1.03 1.05
不å??貸! 不詐é¨?! 不援交! 不æ??交! 不æ??å?«! 不è?ªæ®º! è«?è??æ?®ç¶?援 (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_...

Man-wai Chang ToDie

3/4/2016 1:59:00 PM

0

On 3/4/2016 9:15 PM, jonas.thornvall@gmail.com wrote:
>
> I thought this would sort the property "subarray" nodelinks.
> arr[0].nodelinks.sort();
> But after sort it write out same content as before sort.
> 1,10,11,12,13,14,15,16,17,2,3,4,5,6,7,8,9
> My object something like this.
> arr[k] ={nodelinks : []};

I don't know what you are trying to write or build. I seldom heard
people doing elaborate mathematics with Javascript, which is used mainly
for displaying web-pages.

Are you abusing if not misusing a tool here?

--
@~@ Remain silent. Nothing from soldiers and magicians is real!
/ v \ Simplicity is Beauty! May the Force and farces be with you!
/( _ )\ (Fedora release 23) Linux 4.4.3-300.fc23.x86_64
^ ^ 21:42:01 up 19:51 0 users load average: 1.05 1.03 1.05
不å??貸! 不詐é¨?! 不援交! 不æ??交! 不æ??å?«! 不è?ªæ®º! è«?è??æ?®ç¶?援 (CSSA):
http://www.swd.gov.hk/tc/index/site_pubsvc/page_socsecu/sub_...