<html>
<head>
<title>Linked List</title>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript">
function Node(data) {
this.data = data;
this.frequency =1;
this.next = null;
}
var SList =function SList() {
this.head = new Node("Dummy");
}
SList.prototype.insertLast =function(data) {
var p = this.head;
while (p.next!=null)
p = p.next;
p.next=new Node(data);
}
SList.prototype.insertFirst =function(data) {
var p=new Node(data);
p.next = this.head.next;
this.head.next=p;
}
SList.prototype.traversal=function (){
var p=this.head;
while (p.next != null){
document.write( p.next.data + "("+p.next.frequency+"), ");
p = p.next;
}
}
SList.prototype.orderInsert =function(data) {
var k = this.search( data );
if (k) k.frequency++;
else {
var p = new Node(data);
var q = this.head;
while (q.next!=null && q.next.data<data)
q = q.next;
p.next=q.next;
q.next=p;
}
}
SList.prototype.search= function (data) {
var p = this.head;
while (p.data != data && p.next!=null)
p = p.next;
if (p.data !=data)
return null;
else
return p;
}
var Slist = new SList();
var s=new Array("earthquake","prediction","geology","physics",
"chemistry","biology","mathematics","computer","earth_science",
"chemistry","biology","mathematics","computer","paleomagnetism",
"topology","biology","mathematics","computer","earthquake");
for (var i=0; i<s.length; i++)
Slist.orderInsert(s[i]);
Slist.traversal();
</script>
</body>
</html>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有