博客
关于我
数据结构第三天
阅读量: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基础-函数篇
    查看>>
    python基础---->常用模块
    查看>>
    Python基础(2):控制结构
    查看>>
    Python基础 | 关于“循环”那些事
    查看>>
    python系列【仅供参考】:python之subprocess模块rsync拉取文件
    查看>>
    python系列【仅供参考】:python 远程rdp
    查看>>
    python基础
    查看>>
    Python基本语法与变量类型
    查看>>
    python基本数据类型(容器)- tuple list dict set
    查看>>
    python基本工资的调整方案_Python薪资又涨了!这可咋办!
    查看>>
    Python基准测试和性能分析内存管理和垃圾回收
    查看>>
    Python基于RESTful风格的接口自动化测试实战
    查看>>
    python基于pygame实现跨年烟花效果
    查看>>
    python基于flask搭建http服务(四)—— Docker容器化部署
    查看>>
    python基于flask搭建http服务(二)—— 实现Excel上传、数据清洗、入库
    查看>>
    python基于flask搭建http服务(三)—— 使用gunicorn部署项目
    查看>>
    python基于flask搭建http服务(一)—— 实现数据查询和Excel导出
    查看>>
    Python块键盘/鼠标输入
    查看>>
    Python在正确的时区获取当前时间
    查看>>
    python在心理学研究中的应用有哪些_心理学在线研究可用平台简介和应用进展
    查看>>