Python 数据结构 之 线性表 的链式存储结构

您所在的位置:网站首页 Python线性表代码 Python 数据结构 之 线性表 的链式存储结构

Python 数据结构 之 线性表 的链式存储结构

2024-07-09 02:50| 来源: 网络整理| 查看: 265

用Python 来实现 C语言中 线性表的链式存储结构。

文章转载请注明:  Python 数据结构 之 线性表 的链式存储结构

代码地址

https://github.com/WenkeZhou/PythonDataStructure/blob/master/struct/List/MyLKList.py

# !/usr/bin/env python # -*- coding: utf-8 -*- __author__ = 'MrHero' class SqList(object): def __init__(self, size): self.data = list(None for _ in range(size)) self.length = 0 self.max_size = size def add_item(self, item): """ 添加单个item :param item: :return: """ if self.length < self.max_size: self.data[self.length] = item self.length += 1 else: raise IndexError("List is full !") def create_list(self, tar_list): """ 添加一个list到序列表中 :param tar_list: :return: """ for i, item in enumerate(tar_list): if self.length >= self.max_size: raise IndexError("List is full!") else: self.add_item(tar_list[i]) def delete(self, i): """ 删除位置为i的节点的值 :param i: :return: """ if i > self.length or i self.length or i


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3