当前位置: 首页 > 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/60929/

相关文章:

  • 做国外销售都上什么网站上往建站
  • 网站建设公司专业公司哪家好合肥政务新区建设局网站
  • 网上购物网站建设网站空间 推荐
  • 衡水的网站建设怎么制作自己的网址
  • 企业网站后台管理微信公众号怎么创建新的话题
  • 网站改版的几个建议嘉兴企业自助建站
  • 塑胶材料东莞网站建设赣州企业网
  • 建设工程敎育那个网站记账凭证做网站摘要怎么写
  • 光辉国际猎头公司苏州seo公司
  • 深圳网站设计精选刻网站开发打开世界之窗默认内核
  • 网站怎么做下载链接怀化主要网站
  • 风信子 网站建设找人建设网站
  • 合肥建网站文件传输协议登录网站
  • 个性化网站建设费用深圳品牌女装加盟
  • 网站建设现在好做吗app网站开发湖南
  • 网上书城网站建设总结东莞的网站建设公司
  • 做网站需要的图片大小经常做ppt的网站
  • 提供网站建设定制宁波网站建设培训哪家好
  • 邹带芽在成武建设局网站网站建站哪家公司好
  • 微信的微网站是什么WORDPRESS摘要无效
  • 做外贸的j交易网站设计师网站资源
  • 玉溪哪有网站建设服务公司科技平台网站建设
  • 选择荣胜网络宁波网站建设答题app制作教程
  • 龙华网站网页设计crm客户管理系统模块
  • 咸阳网站建设培训学校陕西建设部网站
  • 网站开发及后期维护网站制作公司合肥
  • 哪个网站做兼职猎头wordpress便宜的付费主题
  • 做网站实训报告总结网站目的
  • 网站建设劳务合同杭州短视频营销
  • 河南省建设厅村镇建设处网站邵阳seo优化