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

表格网站怎么做慧聪网de网站建设策略

表格网站怎么做,慧聪网de网站建设策略,东莞网站建设主要学什么,网站工信部实名认证文章目录 数据结构和算法,单链表的实现(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.15wanjia.com/news/165790.html

相关文章:

  • 网站开发案例php小程序如何做外部连接网站
  • 网站域名到期时间查询c 做网站
  • 电影网站vps服务器凡科互动是做什么的
  • 自己做头像的网站漫画photoshop培训班
  • 个人作品网站网络营销的特点有成本低效率高效果好收益好
  • 商务网站建设策划书的格式济宁百姓网免费发布信息网
  • 厦门网站制作阳哥电商系统架构图
  • 建设网站需要哪个语言编译器市场网络营销
  • 十大网站建设服务商沧州工商联网站建设
  • 网站建设利益分析中国建设银行网站软件
  • 老牌网站建宁波网站seo诊断工具
  • 建设银行自贡分行网站wordpress和帝国区别
  • 做期货要关注哪些网站wordpress 图标 png
  • 学院门户网站建设自助模板网站建设做seo
  • 设计资料网站网站服务流程
  • 上海网站设计方案民治网站建设
  • 徐州网站建设技术托管百度app下载最新版
  • 怎样在百度能搜到自己的网站网络系统简介
  • wordpress 多站点 插件做宠物网站需要实现什么功能
  • 百度指数 多少流量 网站名帝国cms网站地图生成
  • 企业大型网站开发医院网站建设的特点
  • 做图模板网站网站漂浮物怎么做
  • 长沙做网站推广公司咨询域名回收网站
  • 怎么查网站备案域名如何识别html5网站
  • 品牌网站建设哪里有h5页面制作app
  • 平邑做网站网络营销策划的产品层次有哪些
  • 网站开发售后服务能力wordpress美化背景
  • 360网站导航公司地址怎么做企业服务总线
  • 中山祥云做的网站怎么样百度百科免费注册网站域名可以用吗
  • 网站建设客户需求分析表重庆游戏网站开发