How to count the frequency of each word in a JavaScript singly linked list?

2026-04-27 23:461阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计456个文字,预计阅读时间需要2分钟。

How to count the frequency of each word in a JavaScript singly linked list?

%E5%8E%9F%E5%88%9B%E3%80%82%E5%8F%AF%E4%BB%A5%E8%B0%83%E7%94%A8LinkedList%E7%B1%BB%E7%9A%84%E6%96%B9%E6%B3%95orderInsert%28%29%2C%E4%BB%A5%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%B0%8F%E7%9A%84%E9%A1%BA%E5%BA%8F%E5%82%A8%E5%AD%98%E8%8B%B1%E6%96%87%E5%AD%97%E7%AC%A6%E4%B8%B2%E3%80%82%E5%90%8C%E6%97%B6%E8%AE%B0%E5%BD%95%E8%8B%B1%E6%96%87%E5%8D%95%E8%AF%8D%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%E3%80%82%E7%BB%93%E6%9E%9C%E3%80%8CTheclassLinkedListallowsanapplicationtostorestringsinalphabeticalorderbycallingorderInsert%28%29%E3%80%8D

原创。
可以调用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

How to count the frequency of each word in a JavaScript singly linked list?

本文共计456个文字,预计阅读时间需要2分钟。

How to count the frequency of each word in a JavaScript singly linked list?

%E5%8E%9F%E5%88%9B%E3%80%82%E5%8F%AF%E4%BB%A5%E8%B0%83%E7%94%A8LinkedList%E7%B1%BB%E7%9A%84%E6%96%B9%E6%B3%95orderInsert%28%29%2C%E4%BB%A5%E5%AD%97%E6%AF%8D%E5%A4%A7%E5%B0%8F%E7%9A%84%E9%A1%BA%E5%BA%8F%E5%82%A8%E5%AD%98%E8%8B%B1%E6%96%87%E5%AD%97%E7%AC%A6%E4%B8%B2%E3%80%82%E5%90%8C%E6%97%B6%E8%AE%B0%E5%BD%95%E8%8B%B1%E6%96%87%E5%8D%95%E8%AF%8D%E5%87%BA%E7%8E%B0%E7%9A%84%E6%AC%A1%E6%95%B0%E3%80%82%E7%BB%93%E6%9E%9C%E3%80%8CTheclassLinkedListallowsanapplicationtostorestringsinalphabeticalorderbycallingorderInsert%28%29%E3%80%8D

原创。
可以调用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

How to count the frequency of each word in a JavaScript singly linked list?