6、单向链表
来源:互联网 发布:李小璐淘宝店网址 编辑:程序博客网 时间:2024/05/24 07:50
var log = console.log;function Node(element){ this.element = element; this.next = null;}function LList(){ this.head = new Node("head"); this.find = find; this.findPrevious = findPrevious; this.insert = insert; this.remove = remove; this.display = display;}function find(item){ var currNode = this.head; while(currNode.element != item){ currNode = currNode.next; } return currNode;}function findPrevious(item){ var currNode = this.head; while((currNode.next != null) && (currNode.next.element != item)){ currNode = currNode.next; } return currNode;}function insert(newElement, item){ var newNode = new Node(newElement); var current = this.find(item); newNode.next = current.next; current.next = newNode;}function remove(item){ var prevNode = this.findPrevious(item); if(prevNode.next != null){ prevNode.next = prevNode.next.next; }}function display(){ var currNode = this.head; while(currNode.next != null){ log(currNode.next.element); currNode = currNode.next; }}var words = new LList();words.insert("Late", "head");words.insert("in", "Late");words.insert("autumn", "in");words.insert("winner", "autumn");words.display();words.remove("autumn");words.display();
1 0
- 6、单向链表
- 单向链表
- 单向链表倒序
- 单向链表
- 单向链表逆转
- 逆转单向链表
- 单向链表反转
- 单向链表
- 单向链表(ZT)
- 反转单向链表
- 单向链表反转
- 单向链表
- 创建单向链表
- 单向链表反转
- 单向链表
- 单向链表
- 单向链表
- 单向链表
- <jsp:invoke fragment=""/>的理解和使用
- 0102
- iOS开发:AFNetworking和ASIHTTPRequest的比较
- 求教短信协议?
- 斐波那契数列知识小结
- 6、单向链表
- Lua学习笔记(基础二)
- 三角形概率分布
- Codeforces Round #301 (Div. 2)-D. Bad Luck Island(概率dp)
- 数据库查询
- Linux脚本编程之if判断语句
- WM6不支持SendRequestEx,怎么上传HTTP表单?
- 大侠们用eclipse写代码建立项目时用符合j2me wireless toolkit 的目录要求吗?
- ZCMU—1403