博客
关于我
数据结构第三天
阅读量: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/

    你可能感兴趣的文章
    Python 列表(List)概述-ChatGPT4o作答
    查看>>
    Python网络爬虫基础进阶到实战教程
    查看>>
    Python 初学者需要知道的四条建议
    查看>>
    Python 判断字符串是否包含子字符串
    查看>>
    python 判断当前时间是否为零点
    查看>>
    python 利用pandas读取本地中CSV文件的指定列 列名重命名 并保存回本地
    查看>>
    python 利用pyspark读取HDFS中CSV文件的指定列 列名重命名 并保存回HDFS
    查看>>
    python 利用pyttsx3文字转语音
    查看>>
    python 利用已有Ner模型进行数据清洗合并
    查看>>
    python 到大数据开发工程师_如何成为一个大数据开发工程师?
    查看>>
    python 加密解密(base64, AES)
    查看>>
    Python 包管理器和 Node.js
    查看>>
    Python 单词字母顺序不变且所有倒排
    查看>>
    python 反射机制
    查看>>
    python 启动提示IDLE's subprocess didn't make conne...
    查看>>
    python 命令接口_实现“[命令][操作][参数]”样式的命令行接口?
    查看>>
    Python 和 OpenCV.如何检测图像中的所有(填充)圆形/圆形对象?
    查看>>
    Python 和 RabbitMQ - 聆听来自多个渠道的消费事件的最佳方式?
    查看>>
    python编辑器打不开_关于命令ride.py打不开RF,而是打开pycharm编辑器问题解决思路...
    查看>>
    python编译exe同时支持32位_第三周:同时管理64位和32位版本的Python,并用Pyinstaller打包成exe...
    查看>>