博客
关于我
数据结构第三天
阅读量:281 次
发布时间:2019-03-01

本文共 3126 字,大约阅读时间需要 10 分钟。

???????????????

????????????????????????????????????????????????????????????????

1. ???????

??????????????????????????????Python???????????????????????Python???????????????????????????????????????????

?????????????????????????????????????????????????????????????????????????????

2. Python???????

?Python?????????????????????????????????

a = 10b = 20

?????????a?b??????????????????Python?????????????????????????????????????????????????

a, b = b, a

???????????

a, b = 20, 10

????????????????????????????????????????

3. Python?????

??????????????????????????????????????????????

class Node(object):    """???"""    def __init__(self, elem):        self.elem = elem        self.next = None

???????????

  • is_empty()??????????
  • length()????????
  • travel()??????
  • add(item)?????????
  • append(item)?????????
  • insert(pos, item)???????????
  • remove(item)????????
  • search(item)??????????

???????????

class SingleLinkList(object):    """????"""    def __init__(self, node=None):        self.__head = node  # ????    def is_empty(self):        """????????"""        return self.__head is None    def length(self):        """??????"""        count = 0        cur = self.__head        while cur is not None:            count += 1            cur = cur.next        return count    def travel(self):        """???????????"""        cur = self.__head        while cur is not None:            print(cur.elem, end=" ")            cur = cur.next        print()    def add(self, item):        """??????????"""        node = Node(item)        node.next = self.__head        self.__head = node    def append(self, item):        """??????????"""        node = Node(item)        if self.is_empty():            self.__head = node        else:            cur = self.__head            while cur.next is not None:                cur = cur.next            cur.next = node    def insert(self, pos, item):        """??????????"""        if pos <= 0:            self.add(item)        elif pos >= self.length():            self.append(item)        else:            pre = self.__head            count = 0            while count < pos - 1:                pre = pre.next                count += 1            node = Node(item)            node.next = pre.next            pre.next = node    def remove(self, item):        """??????"""        cur = self.__head        pre = None        while cur is not None:            if cur.elem == item:                if pre is None:                    self.__head = cur.next                else:                    pre.next = cur.next                break            pre = cur            cur = cur.next    def search(self, item):        """????????"""        cur = self.__head        while cur is not None:            if cur.elem == item:                return True            cur = cur.next        return False

4. ??????

????????????????

  • ???????????????????????
  • ????????????????????????????
  • ????????????????????????????

??????????????????????????

5. ????????

?????????????????

  • ????????????????????????????????????????????????
  • ???????????????????????????????????????
  • ????????????????????????????????????
  • ?????????????????????????????????????

    转载地址:http://pkto.baihongyu.com/

    你可能感兴趣的文章
    PS —— 精修图像
    查看>>
    PS 图像调整算法——色调分离
    查看>>
    ps 图层混合模式
    查看>>
    ps2025下载安装教程(附安装包)ps2025超详细安装教程
    查看>>
    PSGSuite 项目推荐
    查看>>
    PSR PHP业界规范
    查看>>
    psv黑商店pkgj最新版下载_黑科技p图app下载-黑科技p图最新版下载v1.0.0
    查看>>
    ps命令详解
    查看>>
    PyTorch-Tutorials【pytorch官方教程中英文详解】- 1 Quickstart
    查看>>
    PS网页设计教程XVIII——在Photoshop中设计优雅的乡村酒店或餐厅的网页布局
    查看>>
    PS获取RGB和十六进制的颜色值
    查看>>
    PyTorch 的 10 条顶级知识点
    查看>>
    PS辅助工具Assistor PS
    查看>>
    pt-archiver 归档历史数据及参数详解
    查看>>
    pt-online-schema-change使用详解
    查看>>
    PyTorch 模型性能分析和优化 — 第 2 部分
    查看>>
    PTA L1-011 A-B
    查看>>
    pta l2-1紧急救援(Dijkstra)
    查看>>
    pta求阶乘序列前n项和_学霸整理——求数列的通项公式解法集锦,转化、归纳一文全懂...
    查看>>
    SpringBoot中集成Redis实现对redis中数据的解析和存储
    查看>>