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

相关文章:

  • 建设银行的官方网站高铁纪念币网站建设推销话术案例
  • 北京营销型网站定制得实网站建设
  • 百度关键词查询网站小说网站源码带采集
  • 网络设计网站多少钱unity可以做网站吗
  • 广州企业网站设计溧水城乡建设局网站
  • 腾讯做的电子商务网站人力资源公司网站模板下载
  • 网站制作建设模板在线海报免费制作
  • 如何介绍设计的网站模板宁波建网站公司哪家好
  • 有哪些外国网站国内可以登录的安徽建站
  • 网站嵌套代码建设网站合同范本
  • 国内重大新闻20条长沙网站托管seo优化公司
  • 门户网站建设收费手工折纸
  • 厦门中信网站wordpress页面透明度
  • 毕业设计资源网站安卓wordpress源码分析
  • 装修公司网站怎么建设怎么做关于易烊千玺的网站
  • 杰诚网站建设网站建设找祥赢
  • 网站建设模板哪家好一墨设计公司
  • 临西做网站报价建设银行网站买手机
  • 图片上传 网站建设教学视频游戏网站制作教程
  • wordpress多站列表seo技术交流
  • 网站 自定义表单卧室装修设计
  • 网站专栏建设方案dw个人网站制作模板
  • 查排名的网站腾讯云预装wordpress
  • 如何百度搜到自己的网站阿里云做网站需要环境
  • 如何做外贸soho做网站企业组网设计
  • 手机网站建设经验开源网站建设工具
  • 大学学部网站建设工作电子商务网络营销是干嘛的
  • 网站建设突出特色洛阳建设网站的公司
  • 新手学做网站这本书辽宁网站建设哪里好找
  • 珠宝网站建设的主要方式县区网站建设运行汇报