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

广州平面设计公司有哪些长沙seo排名外包

广州平面设计公司有哪些,长沙seo排名外包,网页设计制作网站首页,重庆做网站建设的公司哪家好文章目录 数据结构和算法,单链表的实现(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/6558/

相关文章:

  • 网站有哪几种类型公众号软文怎么写
  • 360网站排名优化中国贸易网官网手机版
  • 深圳 德 网站建设电商详情页模板免费套用
  • wordpress新增数据字段及展示福州seo推广服务
  • 免费网站设计东莞营销网站建设优化
  • 上海青浦做网站中电建铁路建设公司网站
  • 网站建设知识点的总结360免费wifi怎么连接
  • 公司内部网站创建长春市科学技术局网站
  • 做网站费用怎么付18款禁用软件app破解版
  • 同一服务器如何建设多个网站突唯阿 领先的响应式网站建设平台
  • 北京市朝阳区网站开发公司如何搭建钓鱼网站
  • 网站建设策划包括哪些内容网站开发工程师英文简历
  • 网站开发中应注意哪些问题济宁哪里做网站
  • 嘉盛建设集团官方网站手机如何建网站
  • 免费图片素材网检测网站的seo效果
  • 临沂酒店建设信息网站如何做seo网站
  • 贵阳做网站优化中国建设人才服务信息网是不是正规网站
  • 好的网站设计网站建设有发展吗
  • 个人免费网站怎么建设三站合一网站建设
  • 微信公众平台网站开发ui图标素材网站
  • 做网站能接到模具单吗wordpress文章置顶2篇
  • 网站名称与备案名称不一致中国建设银行企业网上银行登录入口
  • 深圳网站设计深圳设计公司如何在社交网站上做视频推广方案
  • 如何做登录网站wordpress 如何修改关于我们
  • 代做网站的公司有哪些医院网站建设网站
  • 做盈利网站怎么备案wordpress中文名字注册
  • 网站搭建完手机访问校园网站推广方案怎么做
  • 网站使用协议书wordpress盒子
  • 网站建设公司是什么意思做照片书网站
  • 已经备案的域名做电影网站做树状图的网站