Implement a Linked List
Implement a Linked List - SOLUTION
Problem Statement
Implement a Linked List by using a Node class object. Show how you would implement a Singly Linked List and a Doubly Linked List!
Solution
Since this is asking the same thing as the implementation lectures, please refer to those video lectures and notes for a full explanation. The code from those lectures is displayed below:
Singly Linked List
class LinkedListNode(object): def __init__(self,value): self.value = value
self.nextnode = None
a = LinkedListNode(1)
b = LinkedListNode(2)
c = LinkedListNode(3)
a.nextnode = b
b.nextnode = c
Doubly Linked List
class DoublyLinkedListNode(object): def __init__(self,value): self.value = value
self.next_node = None
self.prev_node = None
a = DoublyLinkedListNode(1)
b = DoublyLinkedListNode(2)
c = DoublyLinkedListNode(3)
# Setting b after a
b.prev_node = a
a.next_node = b
# Setting c after a
b.next_node = c
c.prev_node = b
Good Job!
Implement a Linked List的更多相关文章
- C++开发工程师面试题库 200~250道
199 MFC中SendMessage和PostMessage的区别?答:PostMessage 和SendMessage的区别主要在于是否等待应用程序做出消息处理.PostMessage只是把消息 ...
- CLRS10.2-8练习 - 单指针值实现双向链表
要求: Explain how to implement doubly linked lists using only one pointer value x.np peritem instead o ...
- cc150 Chapter 2 | Linked Lists 2.6 Given a circular linked list, implement an algorithm which returns node at the beginning of the loop.
2.6Given a circular linked list, implement an algorithm which returns the node at the beginning of ...
- [TS] Implement a doubly linked list in TypeScript
In a doubly linked list each node in the list stores the contents of the node and a pointer or refer ...
- [TS] Implement a singly linked list in TypeScript
In a singly linked list each node in the list stores the contents of the node and a reference (or po ...
- [LeetCode] Reverse Linked List 倒置链表
Reverse a singly linked list. click to show more hints. Hint: A linked list can be reversed either i ...
- LeetCode 206 Reverse a singly linked list.
Reverse a singly linked list. Hint: A linked list can be reversed either iteratively or recursively. ...
- [LintCode] Delete Node in the Middle of Singly Linked List 在单链表的中间删除节点
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to ...
- [CareerCup] 2.2 Kth to Last Element of Linked List 链表的倒数第k个元素
2.2 Implement an algorithm to find the kth to last element of a singly linked list. 这道题让我们求链表中倒数第k个元 ...
随机推荐
- 第二章 Struts 2的应用
2.1 Struts 2的应用 2.1.1 使用步骤 1.创建web项目,添加jar包,创建helloWorld.jsp页面 2.创建HelloWorldAction ...
- CF #356 div1 A. Bear and Prime 100
题目链接:http://codeforces.com/contest/679/problem/A CF有史以来第一次出现交互式的题目,大致意思为选择2到100中某一个数字作为隐藏数,你可以询问最多20 ...
- STM32学习笔记(四)——串口控制LED(中断方式)
目录: 一.时钟使能,包括GPIO的时钟和串口的时钟使能 二.设置引脚复用映射 三.GPIO的初始化配置,注意要设置为复用模式 四.串口参数初始化配置 五.中断分组和中断优先级配置 六.设置串口中断类 ...
- 苹果笔记本只能上QQ,微信,任何浏览器不能打开网页的问题。
我的笔记本一共遇到过两次这种情况.第一次是浏览器输入域名打不开网页,而输入ip地址可以打开.这就是DNS服务器的问题,解决方法很简单.在系统偏好设置里面找到网络,然后,点击正在连接的网络的高级选项,选 ...
- vue2-loading-bar 一款基于Vue2的进度条插件
自学了N久vue,奈何没有练手项目,终于决心拿个东西来试试手.基于对音乐的热爱,选择的第一个demo是音乐播放器.一般播放器都有进度条,于是无意间找到这个插件,就是vue2-loading-bar,这 ...
- Vue 自定义图片懒加载指令v-lazyload
Vue是可以自定义指令的,最近学习过程中遇见了一个需要图片懒加载的功能,最后参考了别人的代码和思路自己重新写了一遍.以下将详细介绍如何实现自定义指令v-lazyload. 先看如何使用这个指令: &l ...
- Unity 多屏(分屏)显示,Muti_Display
Unity 多屏(分屏)显示,Muti_Display 最近项目有个需求,主要用于在展厅的展示游戏. 比如,在一个很大的展厅,很大的显示屏挂在墙上,我们不可能通过操作墙上那块显示器上的按钮来控制游戏 ...
- 分针网—每日分享: 怎么轻松学习JavaScript
js给初学者的印象总是那么的"杂而乱",相信很多初学者都在找轻松学习js的途径. 我试着总结自己学习多年js的经验,希望能给后来的学习者探索出一条"轻松学习js之路& ...
- Brief introduction to Java String Split 【简单介绍下Java String Split】
Split is a common function in Java. It split a full string to an array based on delimeter. For examp ...
- 用ArrayList(解决约瑟夫问题)
约瑟夫问题(Josephus problem)又称为约瑟夫斯置换,是一个出现在计算机科学和数学中的问题.在计算机编程的算法中,约瑟夫问题类似问题又称为约瑟夫环."丢手绢问题". 据 ...