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

    你可能感兴趣的文章
    php原生代码怎么连表查询,PHP tp5中使用原生sql查询代码实例
    查看>>
    PHP去掉转义符
    查看>>
    php去除字符串开头或末尾的字符(例如逗号)
    查看>>
    php反射api
    查看>>
    PHP反射ReflectionClass、ReflectionMethod 入门教程
    查看>>
    PHP反射机制
    查看>>
    php取当天的最后一秒_Docker快速搭建PHP开发环境详细教程
    查看>>
    php取绝对值
    查看>>
    PHP变量内容的获取
    查看>>
    php各种常用的算法
    查看>>
    php各种缓存策略对比
    查看>>
    RabbitMQ高级特性 - 消息分发(限流、负载均衡)
    查看>>
    php后台“爬虫”模拟登录第三方系统
    查看>>
    php后台的在控制器中就可以实现阅读数增加
    查看>>
    php命令行生成项目结构
    查看>>
    php命名空间
    查看>>
    PHP命名空间带来的干扰
    查看>>
    PHP和MySQL Web开发从新手到高手,第1天-搭建PHP开发环境
    查看>>
    php商店管理系统,基于PHP的商店管理系统.doc
    查看>>
    PHP四大主流框架的优缺点总结
    查看>>