双向链表和普通链表的区别在于,在链表中,一个节点只有链向下一个节点的链接,而在双向链表中,链接是双向的:一个链向下一个元素,另一个链向前一个元素。
双向链表提供了两种迭代列表的方法:从头到尾,或者反过来。我们也可以访问一个特定节点的下一个或前一个元素。在单向链表中,如果迭代列表时错过了要找的元素,就需要回到列表起点,重新开始迭代。这是双向链表的一个优点。
双向链表:单向链表只能向着一个方向遍历链表节点,而在节点指针域中增加了前向指针的双向链表,则可以向着两个方向遍历节点。这使得双向链表也可以在任何一个节点遍历整个链表。
function DoublyLinkedList() { var Node = function(element) { this.element = element; this.next = null; this.prev = null; }; var length = 0, head = null, tail = null; this.append = function(element){ var node = Node(element), current, previous; if(!head){ head = node; tail = node; }else{ current = head; while(current){ previous = current; current = current.next; } node.next = current; current.prev = node; previous.next = node; node.prev = previous; } length++; return true; } this.insert = function(position,element){ if(position > -1 && position < length){ var node = new Node(element), current = head, previous, index = 0; if(position === 0){ if(!head){ head = node; tail = node; }else{ node.next = current; current.prev = node; head = node; } }else if (position === length -1){ current = tail; current.next = node; node.prev = current; }else { while(index++ < position){ previous = current; current = current.next; } node.next = current; previous.next = node; current.prev = node; node.prev = previous; } length++; return true; }else{ return false; } }; this.removeAt = function(position){ if(position > -1 && position < length){ var current = head, index = 0, previous; if (position === 0) { head = current.next; if(length === 1){ tail = null; }else{ head.prev = null; } }else if(position === length - 1){ current = tail; tail = current.prev; tail.next = null; } else{ while(index++ < position){ previous = current; current = current.next; } previous.next = current.next; current.next.prev = previous; }; length-- ; return current.element; }else{ return false; } }; this.remove = function(element){ var current = head, previous; if(current.element === element){ head = current.next; } previous = current; current = current.next; while(current){ if (current.element = element) { previous.next = current.next; current.next.prev = previous; }else{ previous = current; current = current.next; } } return false; }; this.remove = function(){ if (length === 0) { return false; }; var current = head, previous; if(length === 1){ head = null; tail = null; length--; return current.element; } while(current){ previous = current; current = current.next; } previous.next = null; length--; return current.element; }; this.indexOf = function(element){ var current = head, index = 0; while(current && index++ < length){ if (current.element === element) { return index; }; current = current.next; } return false; }; this.isEmpty = function(){ return length === 0; }; this.size = function(){ return length; }; this.toString = function(){ var current = head, string = ''; while(current){ string += current.element; current = current.next; } return string; }; this.getHead = function(){ return head; }; this.getTail = function(){ return tail; }; }
双向循环链表:将双向链表的头尾指针相连,就构成了双向循环链表。这种链表从任意一个节点都可以同时向两个方向进行节点遍历,查询节点的速度也是最快的。
/*双向循环链表*/ function DoublyCircularLinkedList(){ var Node = function(element){ this.element = element; this.next = null; this.prev = null; }; var length = 0, head = null, tail = null; this.append = function(element){ var node = new Node(element), current, previous; if (!head) { head = node; tail = node; head.prev = tail; tail.next = head; }else{ current = head; while(current.next !== head){ previous = current; current = current.next; } current.next = node; node.next = head; node.prev = current; }; length++; return true; }; this.insert = function(position, element){ if(position >= 0 && position <= length){ var node = new Node(element), index = 0, current = head, previous; if(position === 0){ if(!head){ node.next = node; node.tail = node; head = node; tail = node; }else{ current.prev = node; node.next = current; head = node; node.prev = tail; } }else if(position === length){ current = tail; current.next = node; node.prev = current; tail = node; node.next = head; }else{ while(index++ < position){ previous = current; current = current.next; } current.prev = node; node.next = current; previous.next = node; node.prev = previous; } length++; return true; }else{ return false; } }; this.removeAt = function(position){ if(position > -1 && position < length){ var current = head, index = 0, previous; if(position === 0){ current.next.previous = tail; head = current.next; }else if(position === length - 1){ current = tail; current.prev.next = head; head.prev = current.prev; tail = current.prev; }else{ while(index++ < position){ previous = current; current = current.next; } previous.next = current.next; current.next.prev = previous; } length--; return true; }else{ return false; } }; this.remove = function(element){ var current = head, previous, indexCheck = 0; while(current && indexCheck < length){ if(current.element === element){ if(indexCheck === 0){ current.next.prev = tail; head = current.next; }else{ current.next.prev = previous; previous.next = current.next; } length--; return true; } previous = current; current = current.next; indexCheck++; } return false; }; this.remove = function(){ if(length === 0){ return false; } var current = head, previous, indexCheck = 0; if(length === 1){ head = null; tail = null; length--; return current.element; } while(indexCheck++ < length){ previous = current; current = current.next; } previous.next = head; tail = previous.next; length--; return current.element; }; this.indexOf = function(element){ var current = head, index = 0; while(current && index++ < length){ if(current.element === element){ return index; } current = current.next; } return false; }; this.toString = function(){ var current = head, indexCheck = 0, string = ''; while(current && indexCheck < length){ string += current.element; indexCheck++; current = current.next; } return string; }; this.isEmpty = function(){ return length === 0; }; this.getHead = function(){ return head; }; this.getTail = function(){ return tail; }; this.size = function(){ return length; }; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
《魔兽世界》大逃杀!60人新游玩模式《强袭风暴》3月21日上线
暴雪近日发布了《魔兽世界》10.2.6 更新内容,新游玩模式《强袭风暴》即将于3月21 日在亚服上线,届时玩家将前往阿拉希高地展开一场 60 人大逃杀对战。
艾泽拉斯的冒险者已经征服了艾泽拉斯的大地及遥远的彼岸。他们在对抗世界上最致命的敌人时展现出过人的手腕,并且成功阻止终结宇宙等级的威胁。当他们在为即将于《魔兽世界》资料片《地心之战》中来袭的萨拉塔斯势力做战斗准备时,他们还需要在熟悉的阿拉希高地面对一个全新的敌人──那就是彼此。在《巨龙崛起》10.2.6 更新的《强袭风暴》中,玩家将会进入一个全新的海盗主题大逃杀式限时活动,其中包含极高的风险和史诗级的奖励。
《强袭风暴》不是普通的战场,作为一个独立于主游戏之外的活动,玩家可以用大逃杀的风格来体验《魔兽世界》,不分职业、不分装备(除了你在赛局中捡到的),光是技巧和战略的强弱之分就能决定出谁才是能坚持到最后的赢家。本次活动将会开放单人和双人模式,玩家在加入海盗主题的预赛大厅区域前,可以从强袭风暴角色画面新增好友。游玩游戏将可以累计名望轨迹,《巨龙崛起》和《魔兽世界:巫妖王之怒 经典版》的玩家都可以获得奖励。
更新日志
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]