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

    你可能感兴趣的文章
    OSPF 学习
    查看>>
    OSPF 支持的网络类型:广播、NBMA、P2MP和P2P类型
    查看>>
    OSPF 概念型问题
    查看>>
    OSPF 的主要目的是什么?
    查看>>
    SQL Server 存储过程分页。
    查看>>
    OSPF不能发现其他区域路由时,该怎么办?
    查看>>
    OSPF两个版本:OSPFv3与OSPFv2到底有啥区别?
    查看>>
    SQL Server 存储过程
    查看>>
    OSPF在大型网络中的应用:高效路由与可扩展性
    查看>>
    OSPF太难了,这份OSPF综合实验请每位网络工程师查收,周末弯道超车!
    查看>>
    OSPF技术入门(第三十四课)
    查看>>
    OSPF技术连载10:OSPF 缺省路由
    查看>>
    OSPF技术连载11:OSPF 8种 LSA 类型,6000字总结!
    查看>>
    OSPF技术连载13:OSPF Hello 间隔和 Dead 间隔
    查看>>
    OSPF技术连载14:OSPF路由器唯一标识符——Router ID
    查看>>
    OSPF技术连载15:OSPF 数据包的类型、格式和邻居发现的过程
    查看>>
    OSPF技术连载16:DR和BDR选举机制,一篇文章搞定!
    查看>>
    OSPF技术连载17:优化OSPF网络性能利器——被动接口!
    查看>>
    OSPF技术连载18:OSPF网络类型:非广播、广播、点对多点、点对多点非广播、点对点
    查看>>
    OSPF技术连载19:深入解析OSPF特殊区域
    查看>>