How to count the frequency of each word in a JavaScript singly linked list?
- 内容介绍
- 文章标签
- 相关推荐
本文共计368个文字,预计阅读时间需要2分钟。
创新。可以使用LinkedList类的orderInsert()方法,按字母顺序存储英文字符串。同时记录英文单词出现的次数。LinkedList类允许应用程序通过调用orderInsert()方法以字母顺序存储字符串。
原创。可以调用LinkedList类的方法orderInsert(),以字母大小的顺序储存英文字符串。
同时记录英文单词出现的次数
TheclassLinkedListallowsanapplicationtostorestringsinalphabeticalorder
bycallingorderInsert().Thefrequencyforeachwordisalsoprovided.
1.[文件] linked_list_string_frequency.html~2KB 下载(0)
<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>
2.[图片] linked_list_string_frequency.png
本文共计368个文字,预计阅读时间需要2分钟。
创新。可以使用LinkedList类的orderInsert()方法,按字母顺序存储英文字符串。同时记录英文单词出现的次数。LinkedList类允许应用程序通过调用orderInsert()方法以字母顺序存储字符串。
原创。可以调用LinkedList类的方法orderInsert(),以字母大小的顺序储存英文字符串。
同时记录英文单词出现的次数
TheclassLinkedListallowsanapplicationtostorestringsinalphabeticalorder
bycallingorderInsert().Thefrequencyforeachwordisalsoprovided.
1.[文件] linked_list_string_frequency.html~2KB 下载(0)
<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>

