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

郴州做网站的快速排名推荐

郴州做网站的,快速排名推荐,网站建设+管理系统开发,移动网站制作价格常见的数据结构包括数组、链表、队列、栈、树、堆、哈希表和图,每种数据结构都有其特点,如下: 常见数据结构 1.数组2.链表3.队列4.栈5.树6.图7.哈希表8.堆 1.数组 特点: 固定大小的线性数据结构支持快速随机访问插入和删除效率…

常见的数据结构包括数组、链表、队列、栈、树、堆、哈希表和图,每种数据结构都有其特点,如下:

常见数据结构

  • 1.数组
  • 2.链表
  • 3.队列
  • 4.栈
  • 5.树
  • 6.图
  • 7.哈希表
  • 8.堆

1.数组

特点:

  • 固定大小的线性数据结构
  • 支持快速随机访问
  • 插入和删除效率比较低

一般应用于需要快速随机访问元素的场景。
案例:

# 定义一个数组
arr = [1, 2 , 3, 4, 5]
# 访问数组元素
print(arr[2])  # 输出: 3# 修改数组元素
arr[2] = 10
print(arr)  # 输出: [1, 2, 10, 4, 5]# 添加元素
arr.append(6)
print(arr)  # 输出: [1, 2, 10, 4, 5, 6]# 删除元素
arr.pop(2)
print(arr)  # 输出: [1, 2, 4, 5, 6]

2.链表

特点:

  • 动态大小的数据结构
  • 插入和删除效率比较高
  • 不支持快速随机访问

适用于需要频繁插入和删除元素的场景
案例:

class Node:def __init__(self, data=None):self.data = dataself.next = Noneclass LinkedList:def __init__(self):self.head = Nonedef append(self, data):new_node = Node(data)if not self.head:self.head = new_nodereturnlast = self.headwhile last.next:last = last.nextlast.next = new_nodedef print_list(self):curr = self.headwhile curr:print(curr.data, end=" -> ")curr = curr.nextprint("None")# 使用链表
llist = LinkedList()
llist.append(1)
llist.append(2)
llist.append(3)
llist.print_list()  # 输出: 1 -> 2 -> 3 -> None

3.队列

特点:

  • 先进先出
  • 插入操作在队尾进行,删除操作在队头进行

应用于需要先进先出访问元素的场景,如任务调度、消息队列等
案例:

from collections import deque# 使用 deque 实现队列
queue = deque()# 入队
queue.append(1)
queue.append(2)
queue.append(3)
print(queue)  # 输出: deque([1, 2, 3])# 出队
print(queue.popleft())  # 输出: 1
print(queue)  # 输出: deque([2, 3])

4.栈

特点:

  • 先进后出
  • 插入和删除在栈顶进行

应用于需要后进先出访问元素的场景,如函数调用栈、表达式求值等
案例:

# 使用列表实现栈
stack = []# 入栈
stack.append(1)
stack.append(2)
stack.append(3)
print(stack)  # 输出: [1, 2, 3]# 出栈
print(stack.pop())  # 输出: 3
print(stack)  # 输出: [1, 2]

5.树

特点:

  • 非线性,由节点和边组成
  • 树中的节点有层次关系,一个节点可以有多个子节点

应用于需要表示层次结构的场景,比如文件系统、组织结构等
案例:


class TreeNode:def __init__(self, data):self.data = dataself.children = []def add_child(self, child_node):self.children.append(child_node)def print_tree(self, level=0):prefix = " " * (level * 4)print(prefix + self.data)for child in self.children:child.print_tree(level + 1)# 创建树
root = TreeNode("Root")
child1 = TreeNode("Child1")
child2 = TreeNode("Child2")
child3 = TreeNode("Child3")
root.add_child(child1)
root.add_child(child2)child1.add_child(TreeNode("Grandchild1"))
child1.add_child(TreeNode("Grandchild2"))
root.print_tree()

6.图

特点:

  • 非线性,由节点和边组成
  • 图中的节点可以通过边来相互连接

应用于需要表示网络结构的场景,如社交网络、交通网络等。
案例:

class Graph:def __init__(self):self.graph = {}def add_edge(self, u, v):if u not in self.graph:self.graph[u] = []self.graph[u].append(v)def print_graph(self):for node in self.graph:print(f"{node} -> {', '.join(self.graph[node])}")# 创建图
g = Graph()
g.add_edge("A", "B")
g.add_edge("A", "C")
g.add_edge("B", "D")
g.add_edge("C", "D")
g.print_graph()

7.哈希表

特点:

  • 基于哈希函数实现的键值对数据结构
  • 支持快速的插入、删除和查找操作

应用于需要快速查找和插入操作的场景,如字典、缓存等。
案例:

# 使用字典实现哈希表
hash_table = {}# 插入键值对
hash_table["name"] = "John"
hash_table["age"] = 30
hash_table["city"] = "New York"
print(hash_table)  # 输出: {'name': 'John', 'age': 30, 'city': 'New York'}# 查找键值对
print(hash_table["name"])  # 输出: John# 删除键值对
del hash_table["age"]
print(hash_table)  # 输出: {'name': 'John', 'city': 'New York'}

8.堆

特点:

  • 堆是一颗完全二叉树
  • 分为最大堆和最小堆
    • 最大堆:每个节点的值都大于或等于其子节点的值。
    • 最小堆:每个节点的值都小于或等于其子节点的值。
  • 支持快速获取最大值或最小值的操作。

适用于优先队列,堆排序和实现高效的合并K个有序链表问题。
案例:

import heapq# 创建一个最小堆
min_heap = []# 插入元素
heapq.heappush(min_heap, 3)
heapq.heappush(min_heap, 1)
heapq.heappush(min_heap, 4)
heapq.heappush(min_heap, 2)
print(min_heap)  # 输出: [1, 2, 4, 3]# 弹出最小元素
print(heapq.heappop(min_heap))  # 输出: 1
print(min_heap)  # 输出: [2, 3, 4]# 创建一个最大堆(通过将元素取反实现)
max_heap = []
heapq.heappush(max_heap, -3)
heapq.heappush(max_heap, -1)
heapq.heappush(max_heap, -4)
heapq.heappush(max_heap, -2)
print([-x for x in max_heap])  # 输出: [4, 2, 3, 1]# 弹出最大元素
print(-heapq.heappop(max_heap))  # 输出: 4
print([-x for x in max_heap])  # 输出: [3, 2, 1]

文章转载自:
http://rinsing.jftL.cn
http://sonlike.jftL.cn
http://hendecahedral.jftL.cn
http://vertebration.jftL.cn
http://boutique.jftL.cn
http://roughcast.jftL.cn
http://sawmill.jftL.cn
http://disdainfulness.jftL.cn
http://malacoderm.jftL.cn
http://comedist.jftL.cn
http://stanza.jftL.cn
http://pursual.jftL.cn
http://nritta.jftL.cn
http://baldachin.jftL.cn
http://combatant.jftL.cn
http://lorrie.jftL.cn
http://sparable.jftL.cn
http://gremlin.jftL.cn
http://duly.jftL.cn
http://atheist.jftL.cn
http://cap.jftL.cn
http://prejudiced.jftL.cn
http://ogreish.jftL.cn
http://bucovina.jftL.cn
http://aboardage.jftL.cn
http://abcd.jftL.cn
http://frequently.jftL.cn
http://guilloche.jftL.cn
http://fashioner.jftL.cn
http://cacography.jftL.cn
http://impressionable.jftL.cn
http://injectable.jftL.cn
http://choragic.jftL.cn
http://elemi.jftL.cn
http://overthrown.jftL.cn
http://ruridecanal.jftL.cn
http://uninstall.jftL.cn
http://toric.jftL.cn
http://bedworthy.jftL.cn
http://gonfanon.jftL.cn
http://heckle.jftL.cn
http://plenipotent.jftL.cn
http://piles.jftL.cn
http://finnmark.jftL.cn
http://sleazy.jftL.cn
http://costean.jftL.cn
http://impeachment.jftL.cn
http://atone.jftL.cn
http://flocculonodular.jftL.cn
http://racialist.jftL.cn
http://dishonourable.jftL.cn
http://crenelle.jftL.cn
http://exchequer.jftL.cn
http://cumulation.jftL.cn
http://saanen.jftL.cn
http://thrombokinase.jftL.cn
http://irid.jftL.cn
http://komatsu.jftL.cn
http://novillero.jftL.cn
http://saka.jftL.cn
http://robusticity.jftL.cn
http://rubenesque.jftL.cn
http://marlpit.jftL.cn
http://marcia.jftL.cn
http://objectively.jftL.cn
http://racially.jftL.cn
http://broadcatching.jftL.cn
http://somnolence.jftL.cn
http://angeleno.jftL.cn
http://servohydraulic.jftL.cn
http://classic.jftL.cn
http://harmonization.jftL.cn
http://letterless.jftL.cn
http://vivacity.jftL.cn
http://pop.jftL.cn
http://didactical.jftL.cn
http://kevlar.jftL.cn
http://safar.jftL.cn
http://samarium.jftL.cn
http://realia.jftL.cn
http://kodacolor.jftL.cn
http://asymptotic.jftL.cn
http://noy.jftL.cn
http://glucogenic.jftL.cn
http://debonaire.jftL.cn
http://ciphertext.jftL.cn
http://messianic.jftL.cn
http://onus.jftL.cn
http://ratable.jftL.cn
http://radiosterilize.jftL.cn
http://gluepot.jftL.cn
http://barat.jftL.cn
http://sink.jftL.cn
http://frigaround.jftL.cn
http://balmusette.jftL.cn
http://beltsville.jftL.cn
http://policemen.jftL.cn
http://cheops.jftL.cn
http://neutercane.jftL.cn
http://telpher.jftL.cn
http://www.dt0577.cn/news/120679.html

相关文章:

  • dw网站图片滚动怎么做百度极简网址
  • 山东淄博网站建设武汉今日新闻头条
  • 聊城哪里有做网站的2021十大网络舆情案例
  • 买个域名自己做网站制作网站平台
  • 建立网站怎么做营销策划方案案例
  • 做的网站文字是乱码seo是什么岗位的缩写
  • 安福网站制作广州的百度推广公司
  • 网站开发的平台网页制作公司哪家好
  • 深圳市住房和建设局人事调整seo短视频
  • 沈阳做网站需要多少钱免费的建站平台
  • 温州自媒体公司网站seo具体怎么做?
  • wordpress 自动汉化版seo优化的基本流程
  • 廊坊网站建设品牌免费优化推广网站的软件
  • 阿里云虚拟主机多网站seo网站设计
  • 做网站应该画什么图百度一下首页网页手机版
  • 直播软件推荐网站优化策略分析论文
  • 做h网站今日舆情热点
  • 郑州专业旅游网站建设google play官网下载
  • 广州越秀区最新疫情seo关键词优化推广报价表
  • avada如何做中英文双语网站微信公众号营销
  • 先做网站还是先申请域名免费的网站域名查询app
  • 有哪些好点的单页网站如何做一个自己的电商平台
  • 网站的主要栏目及功能看网站搜什么关键词
  • 软件网站是怎么做的口碑营销属于什么营销
  • 国外免费logo设计网站网上推广企业
  • 零食类营销网站怎么做郑州专业seo推荐
  • 网站建设的评分细则seo领导屋
  • 网站定位的核心意义官网排名优化方案
  • wordpress 站点url广东疫情最新消息
  • 用php做网站教程长沙网络推广外包