惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
Darknet – Hacking Tools, Hacker News & Cyber Security
爱范儿
爱范儿
GbyAI
GbyAI
A
About on SuperTechFans
阮一峰的网络日志
阮一峰的网络日志
U
Unit 42
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Secure Thoughts
Security Latest
Security Latest
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
PCI Perspectives
PCI Perspectives
MyScale Blog
MyScale Blog
罗磊的独立博客
Y
Y Combinator Blog
Know Your Adversary
Know Your Adversary
月光博客
月光博客
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recorded Future
Recorded Future
S
Securelist
T
Tor Project blog
Apple Machine Learning Research
Apple Machine Learning Research
人人都是产品经理
人人都是产品经理
WordPress大学
WordPress大学
The GitHub Blog
The GitHub Blog
P
Privacy & Cybersecurity Law Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
雷峰网
雷峰网
Microsoft Security Blog
Microsoft Security Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Project Zero
Project Zero
T
Tailwind CSS Blog
腾讯CDC
C
Cisco Blogs
T
The Exploit Database - CXSecurity.com
The Hacker News
The Hacker News
F
Full Disclosure
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
美团技术团队
N
Netflix TechBlog - Medium
云风的 BLOG
云风的 BLOG
N
News and Events Feed by Topic
C
Cybersecurity and Infrastructure Security Agency CISA
D
Docker
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
T
Threat Research - Cisco Blogs
O
OpenAI News
Cloudbric
Cloudbric

博客园 - 过河卒A

.net控件开发(十一)之.net设计期功能 第一部分 左中右3栏布局中最先显示中栏内容的方法 IE中z-index BUG IE中IMG元素上应用padding的奇特bug 关于String、Function、Array的属性和用法 lisp入门 函数式编程让JS更优美 函数式JavaScript编程指南 JavaScript 随笔汇集 如何杜绝iframe挂马 怎么用javascript进行拖拽(转摘) .net的幕后英雄 (转摘) 微软计划2008年初发布Windows Server2008 微软:将以SQL Server授权拉拢甲骨文客户 微软发布SQL Server 2008测试版 明年上市 微软MSN推出新一代Live服务 能离线编辑博客 谷歌发布GPhone 创始人亲自上阵 微软刘振宇:Windows live for Mobilo带来新机遇 微软招募经理 欲开发下一代照片视频共享服务
javascript实现的数据结构
过河卒A · 2007-12-07 · via 博客园 - 过河卒A

此例是javascript来建立链表。。
并对此进行了排序。。

还可以在GenericList一般链表上进行扩展。
实现各种排序及增,删,改结点。。



<script>
function Node(){
  
this.data=null;
  
this.next=null;
}


function GenericList(){
  
this.head=null;
  
this.current=null
  
//打出所有的链表结点
  this.print= function(){
  
this.current=this.head;
   
while(this.current!=null){
      alert(
this.current.data);
      
this.current=this.current.next;
    }

  
  }
,
  
//建立链表
  this.addHead =function(t){
      
  
      
var node=new Node();
      node.data
=t;
      node.next
=this.head;
      
this.head=node;
 
  }

  
  

}



function SortList(){
//冒泡排序链表 
this.BubbleSort=function()
   
{
     
if(this.head==null||this.head.next==null)
     
{
        
return ;
     }

    
var swapped;
    
do{
    
     
this.previous=null;
     
this.current=this.head;

     
var swapped=false;
     
while(this.current.next!=null)
      
{
       
       
if(this.current.data-this.current.next.data>0)
        
{
       
        
var tmp=this.current.next;
        
this.current.next=this.current.next.next;
        tmp.next
=this.current;
        
if(this.previous==null)
            
{
               
this.head=tmp;
            }

         
else
           
{
               
this.previous.next=tmp;
           }

          
this.previous=tmp;
          swapped
=true;
          
       
       }

       
else
        
{
        
        
this.previous=this.current;
        
this.current=this.current.next;
        
        }

     
     }

     
      
    
    }
while(swapped);
   
   }


}


SortList.prototype
=new GenericList();


(
function Main(){
 
var sl=new  SortList();
 
for(var i=0;i<arguments.length;i++)
 
{sl.addHead(arguments[i]);
 }

 alert(
"未排序的链表");
 sl.print();
 sl.BubbleSort();
  alert(
"已排序的链表  从小到大");
 sl.print();

}
)("1","2","3","4")
</script>