当前位置: 首页 > news >正文

石家庄网站建设哪家便宜网站首页设计教程

石家庄网站建设哪家便宜,网站首页设计教程,甘肃网站怎样备案,济南公司建站模板文章目录 数据结构和算法,单链表的实现(kotlin版)b站视频链接1.定义接口,我们需要实现的方法2.定义节点,表示每个链表节点。3.push(e: E),链表尾部新增一个节点4.size(): Int,返回链表的长度5.getValue(index: Int): E…

文章目录

  • 数据结构和算法,单链表的实现(kotlin版)
    • b站视频链接
    • 1.定义接口,我们需要实现的方法
    • 2.定义节点,表示每个链表节点。
    • 3.push(e: E),链表尾部新增一个节点
    • 4.size(): Int,返回链表的长度
    • 5.getValue(index: Int): E?,获取列表的value值
    • 6.insert(index: Int,e: E),从任意位置插入一个节点
    • 7.remove(index: Int),任意位置删除一个节点
    • 8.完整Demo

数据结构和算法,单链表的实现(kotlin版)

b站视频链接

单链表的实现–koltin版本

1.定义接口,我们需要实现的方法

interface LinkedListAction<E> {fun push(e: E)fun size(): Intfun getValue(index: Int): E?fun insert(index: Int,e: E)fun remove(index: Int)
}

2.定义节点,表示每个链表节点。

data class Node<E>(var next: Node<E>? = null, var value: E)

3.push(e: E),链表尾部新增一个节点

override fun push(e: E) {val newNode = Node(null, e)if (head != null) {
//            val lastNode = node(len - 1)//O(1)时间复杂度last?.next = newNode} else {head = newNode}last = newNodelen++}

4.size(): Int,返回链表的长度

override fun size(): Int {return len}

5.getValue(index: Int): E?,获取列表的value值

    override fun getValue(index: Int): E? {if (index < 0 || index >= len) {throw ArrayIndexOutOfBoundsException("数组越界.....")}return node(index)?.value}//找到对应index下标的节点。private fun node(index: Int): Node<E>? {var h = head//O(n)时间复杂度for (i in 0 until index) {h = h?.next}return h}

6.insert(index: Int,e: E),从任意位置插入一个节点

override fun insert(index: Int, e: E) {val newNode = Node(null, e)//考虑边界if (index == 0) {val h = headhead = newNodenewNode.next = h} else {//考虑最后一个位置val prev = node(index - 1)val next = prev?.nextprev?.next = newNodenewNode.next = next}len++}//找到对应index下标的节点。private fun node(index: Int): Node<E>? {var h = head//O(n)时间复杂度for (i in 0 until index) {h = h?.next}return h}

7.remove(index: Int),任意位置删除一个节点

override fun remove(index: Int) {if (index < 0 || index >= len) {throw ArrayIndexOutOfBoundsException("数组越界.....")}if (index == 0) {val h = headhead = h?.nexth?.next = null} else {val prev = node(index - 1)val current = prev?.nextprev?.next = current?.nextcurrent?.next = null}len--}//找到对应index下标的节点。private fun node(index: Int): Node<E>? {var h = head//O(n)时间复杂度for (i in 0 until index) {h = h?.next}return h}

8.完整Demo

package day1class LinkedList<E> : LinkedListAction<E> {//头指针private var head: Node<E>? = null//优化时间复杂度private var last: Node<E>? = null//集合的长度private var len = 0override fun push(e: E) {val newNode = Node(null, e)if (head != null) {
//            val lastNode = node(len - 1)//O(1)时间复杂度last?.next = newNode} else {head = newNode}last = newNodelen++}//找到对应index下标的节点。private fun node(index: Int): Node<E>? {var h = head//O(n)时间复杂度for (i in 0 until index) {h = h?.next}return h}override fun size(): Int {return len}override fun getValue(index: Int): E? {if (index < 0 || index >= len) {throw ArrayIndexOutOfBoundsException("数组越界.....")}return node(index)?.value}override fun insert(index: Int, e: E) {val newNode = Node(null, e)//考虑边界if (index == 0) {val h = headhead = newNodenewNode.next = h} else {//考虑最后一个位置val prev = node(index - 1)val next = prev?.nextprev?.next = newNodenewNode.next = next}len++}override fun remove(index: Int) {if (index < 0 || index >= len) {throw ArrayIndexOutOfBoundsException("数组越界.....")}if (index == 0) {val h = headhead = h?.nexth?.next = null} else {val prev = node(index - 1)val current = prev?.nextprev?.next = current?.nextcurrent?.next = null}len--}}
http://www.yayakq.cn/news/766344/

相关文章:

  • 江苏住房城乡建设部网站外链论坛
  • 长沙企业网站开发深圳企业招聘信息最新招聘信息
  • 有做a50期货的网站朝阳淘宝网站建设
  • 帮企业建网站步骤wordpress性能太差
  • Paas网站建设关键词批量调词软件
  • 网站百度知道2014 网站建设
  • 网站从建设到上线流程图凡客诚品 v官网
  • 知名网站设计欣赏杭州外贸公司
  • 佳木斯企业网站建设检察院加强网站建设
  • 如何学好网站开发开发板在null不可用
  • 网站开发流行吗logo在线设计制作工具
  • 规划营销型的网站结构分销渠道
  • 岑巩网站建设企业网站内容运营
  • 网站建设最好的书籍是学做面食最好的网站
  • 泰州泛亚信息做网站怎么样安徽省住房建设工程信息网站
  • 秦皇网站建设科讯怎么建设网站
  • 怎么样建网站啊彩页设计网站
  • 响应式网站源码手机建站平台淘客
  • 免费建网站 高校社团官方网站温州小程序制作
  • 网站的icp 备案信息北京建设网官网资格证
  • 2008 .net 网站 目录 权限管理定制棺材网站
  • 郑州区块链数字钱包网站开发过程网站开发背景论文
  • 常熟住房和城乡建设局网站旅游网站开发需求分析
  • wordpress数据库替换命令seo外链资源
  • 网站建设与运营答案怎样做网站推广啊
  • 新建网站需要多少钱网站制作收费明细表
  • 织梦下载网站模板网站开发要求有哪些
  • 万站群cms公司形象墙设计制作
  • wordpress搭建视频站怎样营销网站
  • 深圳市坪山区住房和建设局网站wordpress 用户修改密码