An ordered list of tables implemented with JavaScript

Source: Internet
Author: User
Javascript

Using JavaScript to imitate the ordered list of Java implementation, to achieve the object by one of the properties of the object sorting.

<script>


function Link1 () {}
Link1.prototype.obj=null;
Link1.prototype.next1=new Link1 ();
function Link1.prototype.Link1 (object) {
Obj=object;
}


function SortedList () {}
Sortedlist.prototype.first=new Link1 ();
function SortedList.prototype.SortedList (linkarr,nm) {
var sortedlist=new sortedlist ();
Sortedlist.first=null;
for (j=0;j<linkarr.length;j++) {

Sortedlist.insert (LINKARR[J],NM);
}
}
var f=new sortedlist ();
function SortedList.prototype.insert (lnk,nm) {

var previous1=null;
var Current1=f.first;

  while (current1.obj!=null&&lnk.obj[nm]>current1.obj[nm]) {
    previous1= Current1;
    current1=current1.next1;
 
 
  if (previous1==null) {
   f.first=lnk;
 }else{
   privious1=new Link1 ();
   previous1.next1=lnk;
 }
  Lnk.next1=current1;
}
Function SortedList.prototype.remove (lnk) {
 var temp=new Link1 ();
 temp=f.first;
 f.first=f.first.next1;
 return temp;
}
Function Objtemp () {}
Objtemp.prototype.num=0
Objtemp.prototype.s= "";
var objarr=new Array ();
Objarr[0]=new Link1 ();
Objarr[0].obj=new objtemp ();
Objarr[0].obj.num=1;
objarr[0].obj.s= "First";
Objarr[1]=new Link1 ();
Objarr[1].obj=new objtemp ();
objarr[1].obj.num=10;
objarr[1].obj.s= "Second";
Objarr[2]=new Link1 ();
Objarr[2].obj=new objtemp ();
Objarr[2].obj.num=9;
objarr[2].obj.s= "Third";

Objarr[3]=new Link1 ();
Objarr[3].obj=new objtemp ();
objarr[3].obj.num=19;
objarr[3].obj.s= "Fourth";
var slist=new sortedlist ();
Slist. SortedList (Objarr, "num");
var psh=new Array ();
for (i=0;i<4;i++) {
Psh[i]=slist.remove ();
Alert (psh[i].obj.num+psh[i].obj.s+ "---psh");
}


</script>




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.