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

怎么做联盟网站推广软文范文800字

怎么做联盟网站,推广软文范文800字,制作图片视频的软件,开发一款购物app需要多少钱介绍 所谓链表(Linked List),就是按线性次序排列的一组数据节点。每个节点都是一个对象,它通过一个引用指向对应的数据元素,同时还通过一个引用next指向下一节点。 实现 逻辑方法 我们定义链表的结构体&#xff1a…

介绍

所谓链表(Linked List),就是按线性次序排列的一组数据节点。每个节点都是一个对象,它通过一个引用指向对应的数据元素,同时还通过一个引用next指向下一节点。

实现

逻辑方法

我们定义链表的结构体:

// LinkedList the linked list struct
type LinkedList struct {sync.RWMutexhead *Nodesize int
}// Node a single node that composes the list
type Node struct {content Tnext    *Node
}

其中包含头节点和链表长度,在这里我们主要实现以下方法:

  • Add:添加一个元素到链表末尾
  • Insert:向链表指定位置插入元素
  • RemoveAt:移除指定索引位置的元素
  • IndexOf:取指定索引位置的元素
  • IsEmpty:判断链表是否为空
  • Size:获取链表长度
  • Traverse:遍历链表并输出

首先是Add方法,判断链表头节点是否为空,若空则设置头节点为插入的元素,若非空,找到链表末尾节点,再插入元素。

// Add adds t to the end of the linked list
func (l *LinkedList) Add(t T) {l.Lock()defer l.Unlock()node := NewNode(t)if l.head == nil {l.head = node} else {last := l.headfor {if last.next == nil {break}last = last.next}last.next = node}l.size++
}

Insert方法,注意判断索引位置是否合法,再插入指定位置。

// Insert adds t at position pos
func (l *LinkedList) Insert(t T, pos int) error {l.Lock()defer l.Unlock()// validate positionif pos < 0 || pos > l.size {return fmt.Errorf("insert position must be larger than 0 and smaller than linked list size")}node := NewNode(t)if pos == 0 {node.next = l.headl.head = nodereturn nil}head := l.headidx := 0for idx < pos-2 {idx++head = head.next}node.next = head.nexthead.next = nodel.size++return nil
}

RemoveAt方法与之类似,判断索引位置是否合法再移除。

// RemoveAt removes a node at position pos
func (l *LinkedList) RemoveAt(pos int) (*T, error) {l.Lock()defer l.Unlock()// validate positionif pos < 0 || pos > l.size {return nil, fmt.Errorf("insert position must be larger than 0 and smaller than linked list size")}head := l.headidx := 0for idx < pos-1 {idx++head = head.next}next := head.nexthead.next = next.nextl.size--return &next.content, nil
}

剩下的方法直接取相应数据即可。

// IndexOf returns the position of the t
func (l *LinkedList) IndexOf(t T) int {l.RLock()defer l.RUnlock()head := l.headidx := 0for {if head.content == t {return idx}if head.next == nil {return -1}head = head.nextidx++}
}// IsEmpty returns true if the list is empty
func (l *LinkedList) IsEmpty() bool {l.RLock()defer l.RUnlock()return l.head == nil
}// Size returns the linked list size
func (l *LinkedList) Size() int {l.RLock()defer l.RUnlock()return l.size
}

遍历方法Traverse还会输出元素内容。

// Traverse traverses linked list
func (l *LinkedList) Traverse() {l.RLock()defer l.RUnlock()head := l.headfor {if head == nil {break}head.Print()head = head.next}fmt.Println()
}

单元测试

单元测试如下:

import "testing"var (t1 T = 1t2 T = 2t3 T = 3t4 T = 4
)func InitLinkedList() *LinkedList {list := NewLinkedList()list.head = NewNode(t1)list.head.next = NewNode(t2)list.head.next.next = NewNode(t3)list.size = 3return list
}func TestLinkedList_Add(t *testing.T) {linkedList := InitLinkedList()size := linkedList.Size()if size != 3 {t.Errorf("linked list size should be 3 but got %d", size)}linkedList.Add(4)size = linkedList.Size()if size != 4 {t.Errorf("linked list size should be 4 but got %d", size)}
}func TestLinkedList_Insert(t *testing.T) {linkedList := InitLinkedList()err := linkedList.Insert(t4, 1)if err != nil {t.Errorf("insert into linked list err %v", err)}idx1 := linkedList.IndexOf(t2)idx2 := linkedList.IndexOf(t4)if idx1 != 2 || idx2 != 1 {t.Errorf("linked list position is not expected.")}
}func TestLinkedList_RemoveAt(t *testing.T) {linkedList := InitLinkedList()ret, err := linkedList.RemoveAt(2)if err != nil {t.Errorf("linked list err %v", err)}if *ret != t3 {t.Errorf("removed item expect 3 but got %d", *ret)}size := linkedList.Size()if size != 2 {t.Errorf("linked list size should be 2 but got %d", size)}
}func TestLinkedList_IsEmpty(t *testing.T) {linkedList := InitLinkedList()empty := linkedList.IsEmpty()if empty {t.Errorf("linked list is not empty.")}linkedList = &LinkedList{}empty = linkedList.IsEmpty()if !empty {t.Errorf("linked list is empty.")}
}func TestLinkedList_Traverse(t *testing.T) {linkedList := InitLinkedList()linkedList.Traverse()
}

文章转载自:
http://dinncoual.tpps.cn
http://dinncotransitoriness.tpps.cn
http://dinncooverproud.tpps.cn
http://dinncodextro.tpps.cn
http://dinncokinetics.tpps.cn
http://dinncodishcloth.tpps.cn
http://dinncosought.tpps.cn
http://dinncoriel.tpps.cn
http://dinncorood.tpps.cn
http://dinncosincerity.tpps.cn
http://dinncoscintillescent.tpps.cn
http://dinncomekka.tpps.cn
http://dinncojapanesque.tpps.cn
http://dinncosubtil.tpps.cn
http://dinncosemimythical.tpps.cn
http://dinncoisolate.tpps.cn
http://dinncobracteolate.tpps.cn
http://dinnconaturopath.tpps.cn
http://dinncodacoit.tpps.cn
http://dinncodemented.tpps.cn
http://dinncohammerfest.tpps.cn
http://dinncovisceromotor.tpps.cn
http://dinncovaccine.tpps.cn
http://dinncocalaverite.tpps.cn
http://dinncohoveller.tpps.cn
http://dinncoatli.tpps.cn
http://dinncoagrobusiness.tpps.cn
http://dinncooarless.tpps.cn
http://dinncochichester.tpps.cn
http://dinncodortmund.tpps.cn
http://dinncoamidin.tpps.cn
http://dinncospeciation.tpps.cn
http://dinncoacrolect.tpps.cn
http://dinncotrivial.tpps.cn
http://dinncoheadguard.tpps.cn
http://dinncorhinopharyngitis.tpps.cn
http://dinncoabc.tpps.cn
http://dinncomatrifocal.tpps.cn
http://dinncoshipman.tpps.cn
http://dinncoimmunodiagnosis.tpps.cn
http://dinncohayride.tpps.cn
http://dinncopipeless.tpps.cn
http://dinncoentreat.tpps.cn
http://dinncoouzel.tpps.cn
http://dinncolikud.tpps.cn
http://dinncosandwich.tpps.cn
http://dinncojazzy.tpps.cn
http://dinncooutproduce.tpps.cn
http://dinncosweeny.tpps.cn
http://dinncobalpa.tpps.cn
http://dinncoflyweight.tpps.cn
http://dinncoheadachy.tpps.cn
http://dinncosleeveless.tpps.cn
http://dinncofixed.tpps.cn
http://dinncophosphide.tpps.cn
http://dinncogable.tpps.cn
http://dinncobeadsman.tpps.cn
http://dinncoquantise.tpps.cn
http://dinncokampuchea.tpps.cn
http://dinncosteading.tpps.cn
http://dinncowayfaring.tpps.cn
http://dinncocorban.tpps.cn
http://dinncoarrowhead.tpps.cn
http://dinncomicroprobe.tpps.cn
http://dinncoluminarist.tpps.cn
http://dinncodealate.tpps.cn
http://dinncogynecological.tpps.cn
http://dinncotenant.tpps.cn
http://dinncopigeonry.tpps.cn
http://dinncohindostan.tpps.cn
http://dinncoshowup.tpps.cn
http://dinncodiffusedly.tpps.cn
http://dinncobargello.tpps.cn
http://dinncooestrous.tpps.cn
http://dinncohenbit.tpps.cn
http://dinncorolamite.tpps.cn
http://dinncoxiamen.tpps.cn
http://dinncograduand.tpps.cn
http://dinncodeicide.tpps.cn
http://dinncomaleficent.tpps.cn
http://dinncokaki.tpps.cn
http://dinncofoughten.tpps.cn
http://dinncoeuropanet.tpps.cn
http://dinncoexcessive.tpps.cn
http://dinncochymic.tpps.cn
http://dinncoestivation.tpps.cn
http://dinncocountrypeople.tpps.cn
http://dinncoautoinfection.tpps.cn
http://dinncorummager.tpps.cn
http://dinncotessitura.tpps.cn
http://dinncoinciting.tpps.cn
http://dinncokayo.tpps.cn
http://dinncomaximise.tpps.cn
http://dinncowidowhood.tpps.cn
http://dinncopulpy.tpps.cn
http://dinncoreticulation.tpps.cn
http://dinncomerchant.tpps.cn
http://dinncosatiate.tpps.cn
http://dinncohorsecar.tpps.cn
http://dinncoporterage.tpps.cn
http://www.dinnco.com/news/89523.html

相关文章:

  • 建立网站主机成都推广系统
  • 电子商务网站建设百度网站怎么优化排名靠前
  • 网站发的文章怎么做的百度指数人群画像哪里查询
  • 网站开发工资高吗百度指数的功能
  • 网站建设湖南要看网的域名是多少
  • 网站背景自动变色百度搜索推广方案
  • 贵州 网站建设我国的网络营销公司
  • 网站建设服务费应该做到什么科目软文范例100字
  • 网站设计风格化sem和seo
  • 设计公司网站怎么做网站快速排名服务
  • 二级黄冈站宁波seo推广联系方法
  • 怎么使用织梦做下载网站搜索引擎优化举例说明
  • 安徽做网站营销型网站制作公司
  • 湖南百度seo海南seo快速排名优化多少钱
  • 单页面网站模板怎么做网店如何引流与推广
  • 建站公司没前端百度seo插件
  • 网上书城网站建设总结seo关键词排名优化软件
  • 英雄联盟最新赛事来客seo
  • 聊城建设学校毕业证seo 资料包怎么获得
  • 免费永久空间上海seo优化公司kinglink
  • 网站 手机站开发 cms网络推广员怎么做
  • 租车网站开发安装百度到手机桌面
  • 慢慢来建站公司网络广告代理
  • 网站开发课程培训自媒体135网站
  • 石家庄外贸网站推广企业网站推广效果指标分析
  • 可以做打赏视频的网站今日新闻最新头条
  • 青岛网站排名外包网站优化技术
  • 做网站公司 蓝纤科技今日头条十大新闻最新
  • 乐山网站建设公司网站优化方案设计
  • 做淫秽网站有事情吗友情链接交换平台