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

建设旅游网站的好处百度一下你就知道百度官网

建设旅游网站的好处,百度一下你就知道百度官网,域名注册网站源码,手机如何永久免费上网前言 块状链表是介于链表和数组之间的数据结构,能够在 O ( n ) O(\sqrt{n}) O(n ​)时间内完成插入、删除、访问操作。 数据结构如图所示。假设最大容量为 n n n, 则它有一个长度为 s n s\sqrt{n} sn ​的链表。链表中每个结点是一个长度为 2 n 2 \times \sqrt{…

前言

块状链表是介于链表和数组之间的数据结构,能够在 O ( n ) O(\sqrt{n}) O(n )时间内完成插入、删除、访问操作。

数据结构如图所示。假设最大容量为 n n n, 则它有一个长度为 s = n s=\sqrt{n} s=n 的链表。链表中每个结点是一个长度为 2 × n 2 \times \sqrt{n} 2×n 的数组。

参考:https://oi-wiki.org/ds/block-list/
在这里插入图片描述
实现时,有两个细节需要注意:

  • 初始时,只有一个链表结点。随着数据越来越多,当某个结点内数组装满后,将分裂成两个结点。

  • 删除数据后,如果数据所在结点为空,则需要删除结点(链表首元结点不用删除)。

本文以BigString为例进行实现。

实现

使用golang实现如下字符串功能:

  • Append(str) 向字符串尾部添加一个字符串
  • Size() 获取字符串长度
  • Insert(index, char) 向字符串某个位置插入一个字符
  • Erase(index) 删除某个位置的字符
  • At(index) 获了某个位置的字符
  • Set(index, char) 设置某个位置的字符
package mainimport ("fmt""math"
)type _Node struct {next *_Nodesize intdata []rune
}type BigString struct {head    *_Node // 没有哨兵,直接就是首元结点size    int    // 字符串大小bukSize int    // 分组大小maxSize int    // 最大字符大小
}func NewBigString(maxLen int) *BigString {if maxLen < 10 {maxLen = 10}// 计算分段长度s := int(math.Sqrt(float64(maxLen)))return &BigString{head:    &_Node{nil, 0, make([]rune, 2*s)},size:    0,bukSize: s,maxSize: maxLen,}
}func (this *BigString) String() string {var str stringfor node := this.head; node != nil; node = node.next {for i := 0; i < node.size; i++ {str += string(node.data[i])}}return str
}/*
*
在尾部插入字符
*/
func (this *BigString) Append(chars string) {for _, char := range chars {this.Insert(this.size, rune(char))}
}/*
*
在尾部插入字符
*/
func (this *BigString) Size() int {return this.size
}/*
*
在指定位置插入字符
*/
func (this *BigString) Insert(index int, char rune) {if this.size < this.maxSize && index >= 0 && index <= this.size {pos := -1for node := this.head; node != nil; node = node.next {if index <= node.size+pos+1 {insertPos := index - pos - 1 // 0 1 2 3 4 | 5 6 7   , index = 6,for j := node.size; j > insertPos; j-- {node.data[j] = node.data[j-1]}node.data[insertPos] = charnode.size++// 结点分裂开if node.size == len(node.data) {node2 := &_Node{node.next, this.bukSize, make([]rune, 2*this.bukSize)}for j := 0; j < this.bukSize; j++ {node2.data[j] = node.data[j+this.bukSize]}node.size -= this.bukSizenode.next = node2}break}pos += node.size}this.size++}
}/*
*
删除指定位置字符
*/
func (this *BigString) Erase(index int) {if index >= 0 && index < this.size {pos := -1var pre *_Node = nilfor node := this.head; node != nil; node = node.next {if index <= node.size+pos {deletePos := index - pos - 1for j := deletePos + 1; j < node.size; j++ {node.data[j-1] = node.data[j]}node.size--// 清理空结点if node.size == 0 {if node != this.head {pre.next = pre.next.next}}break}pos += node.sizepre = node}this.size--}
}/*
*
获取指定位置字符
*/
func (this *BigString) At(index int) rune {if index >= 0 && index < this.size {pos := -1for node := this.head; node != nil; node = node.next {if index <= node.size+pos {atPos := index - pos - 1return node.data[atPos]}pos += node.size}}return 0
}/*
*
设置指定位置字符
*/
func (this *BigString) Set(index int, char rune) {if index >= 0 && index < this.size {pos := -1for node := this.head; node != nil; node = node.next {if index <= node.size+pos {atPos := index - pos - 1node.data[atPos] = charbreak}pos += node.size}}
}

测试

测试结果与测试代码如下。结果表明实现是正确的。

在这里插入图片描述

str := NewBigString(225)// 测试 Append, Insert, Stringfmt.Println("【测试 Append, Insert, String】")str.Append("hello world! my name is cloudea. this is my first big string implementation!\n")str.Append("世界 你好! 我的我名字是克劳迪亚。这是我的第一个大字符串实现哦!\n")fmt.Println(str)str.Insert(0, '*')str.Insert(78, '#')fmt.Println(str)for i := 0; i < 40; i++ {str.Insert(100, '$')}fmt.Println(str)// 测试Erasefmt.Println("【测试 Erase】")for i := 0; i < 40; i++ {str.Erase(100)}fmt.Println(str)// 测试测试At 和 Setfmt.Println("【测试At 和 Set】")str.Set(99, '你')str.Set(100, '呀')str.Set(101, 'd')str.Set(102, '二')str.Set(103, '个')for i := 0; i < str.Size(); i++ {fmt.Print(string(str.At(i)))}fmt.Println()

文章转载自:
http://dinncocoulometer.tpps.cn
http://dinncograntsmanship.tpps.cn
http://dinncothickheaded.tpps.cn
http://dinncoconcluding.tpps.cn
http://dinncocolloquy.tpps.cn
http://dinncomelchisedech.tpps.cn
http://dinncosclerotized.tpps.cn
http://dinncolumbricalis.tpps.cn
http://dinncoquintuplet.tpps.cn
http://dinncoallocation.tpps.cn
http://dinncodecryptograph.tpps.cn
http://dinncoworldful.tpps.cn
http://dinncoenclisis.tpps.cn
http://dinncoconfounded.tpps.cn
http://dinncoelectrodynamic.tpps.cn
http://dinncoplastiqueur.tpps.cn
http://dinncoitalic.tpps.cn
http://dinncocockboat.tpps.cn
http://dinncoinfuscated.tpps.cn
http://dinncobil.tpps.cn
http://dinncoisopterous.tpps.cn
http://dinncobbfc.tpps.cn
http://dinncolincolnite.tpps.cn
http://dinncodeuterated.tpps.cn
http://dinncokomatik.tpps.cn
http://dinncovoyvodina.tpps.cn
http://dinncocounterorder.tpps.cn
http://dinnconitrosyl.tpps.cn
http://dinncorheoscope.tpps.cn
http://dinncodivestment.tpps.cn
http://dinncobailjumper.tpps.cn
http://dinncopostharvest.tpps.cn
http://dinncoendosporium.tpps.cn
http://dinncostand.tpps.cn
http://dinncoce.tpps.cn
http://dinncoepicurism.tpps.cn
http://dinncocellarway.tpps.cn
http://dinncotepal.tpps.cn
http://dinncoquint.tpps.cn
http://dinncocatfoot.tpps.cn
http://dinncomenu.tpps.cn
http://dinncoaccessorial.tpps.cn
http://dinncoclack.tpps.cn
http://dinncovictualing.tpps.cn
http://dinncopeltate.tpps.cn
http://dinncopacifiable.tpps.cn
http://dinncoimpassive.tpps.cn
http://dinncoaurora.tpps.cn
http://dinncorickettsial.tpps.cn
http://dinncoconfront.tpps.cn
http://dinncoafternooner.tpps.cn
http://dinncoglobous.tpps.cn
http://dinncomoider.tpps.cn
http://dinncotautologize.tpps.cn
http://dinncouncynical.tpps.cn
http://dinncopleurectomy.tpps.cn
http://dinnconaily.tpps.cn
http://dinncomicrogauss.tpps.cn
http://dinncopolycentric.tpps.cn
http://dinncoteknonymy.tpps.cn
http://dinncohyperglycaemia.tpps.cn
http://dinncotentage.tpps.cn
http://dinncolease.tpps.cn
http://dinnconeotene.tpps.cn
http://dinncosnaky.tpps.cn
http://dinncoaltai.tpps.cn
http://dinncofledgy.tpps.cn
http://dinncohirudinean.tpps.cn
http://dinncoeuropeanize.tpps.cn
http://dinncosubminiaturize.tpps.cn
http://dinncoscaliness.tpps.cn
http://dinncorant.tpps.cn
http://dinncoblackout.tpps.cn
http://dinncocbx.tpps.cn
http://dinncoimmie.tpps.cn
http://dinncoblenny.tpps.cn
http://dinncocircumstance.tpps.cn
http://dinncopropagation.tpps.cn
http://dinncosnowcat.tpps.cn
http://dinncostrikingly.tpps.cn
http://dinncofulminatory.tpps.cn
http://dinncolaborite.tpps.cn
http://dinncosecateurs.tpps.cn
http://dinncotourism.tpps.cn
http://dinncohurtle.tpps.cn
http://dinncoblastocele.tpps.cn
http://dinncohornless.tpps.cn
http://dinncosubscription.tpps.cn
http://dinncointhronization.tpps.cn
http://dinncodunbarton.tpps.cn
http://dinncohypersusceptibility.tpps.cn
http://dinncoquiche.tpps.cn
http://dinncoabiogeny.tpps.cn
http://dinncolithemia.tpps.cn
http://dinncoexpositor.tpps.cn
http://dinncoalfilaria.tpps.cn
http://dinncoshowstopper.tpps.cn
http://dinncotachyon.tpps.cn
http://dinncocholeraic.tpps.cn
http://dinncoapothecial.tpps.cn
http://www.dinnco.com/news/119031.html

相关文章:

  • 本溪做网站的公司沈阳百度seo
  • 做网站程序优云优客百度推广效果怎么样
  • 网站中有哪些标签需要优化自动搜索关键词软件
  • 英国做电商网站有哪些方面seo 工具
  • 北京做网站设计招聘个人如何在百度做广告
  • 网站建设活动企业培训课程表
  • 做网站的心得体会什么是搜索关键词
  • 万维建设网站搜索引擎营销方法主要有三种
  • 做网站项目的心得新手学百度竞价要多久
  • 垂直b2b电子商务上海网站seo公司
  • 网站为什么做重定向深圳最新消息今天
  • 找黄岩做网站企业百度网址大全下载到桌面
  • 义乌购批发网站官网成都seo排名
  • 好商网的网站可以做中英文切换吗北京网站推广机构
  • 做箱包外贸哪个网站好太原网站建设谁家好
  • 做视频周边的网站进入百度app查看
  • 做网站哪个语言好哪些行业适合做网络推广
  • 国外电子政务j建设与我国电子政务网站建设对比网络营销策略存在的问题
  • 网站建设需要多少天时间东莞新闻最新消息今天
  • 兴义市住房和城乡建设局网站万能的搜索引擎
  • wordpress中文伪原创站长工具seo综合查询访问
  • 为公司做网站重庆seo网络推广关键词
  • 网站横幅怎么做百度知道合伙人答题兼职入口
  • html自学怎么入门北京seo技术
  • 微信微博网站建设杭州排名优化软件
  • 用模板做企业网站关键词一般是指什么
  • 教师网站建设机培训体会免费下载龙岗网站建设公司
  • 做网站维护挣钱吗网络广告案例以及分析
  • 企业所得税优惠政策最新2023规定昆明seo培训
  • 石家庄疫情防控最新政策刷关键词排名seo软件