Get the App
SLTechnology News&Howtos  ›  Development  › 

How to make ​ use Python to imitate C language to realize the sequential storage structure of linear table

Shulou Source: shulou.com Published: 2022-06-01 01:38:43 09月21日 Update

Today, I would like to share with you how to use Python to emulate the C language to achieve linear table sequential storage structure of the relevant knowledge points, detailed content, clear logic, I believe that most people are too aware of this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

Code:

#! / usr/bin/env python#-*-coding: utf-8-*-_ _ author__ = 'MrHero' class Node (object): the storage structure of the linear table is similar to the chain storage structure of the C language def _ init__ (self) Data=None): self.data = data self.next = None class LKList (object): "specific operation of the linear table"def _ _ init__ (self):"is equivalent to initializing the linear table, that is, creating a header node with an empty header node. The created table with position number 0 is: header node [0]-> node [1]-> node [2]-> node [3]-> node [4]: return: "self.L = Node (None) self.L.next = None self.length = 0 def is_empty (self):" determine the length of the new table: return: " "return self.length = = 0 def get_length (self):" get the length of the new table of the line: return: "return self.length def insert (self I Elem): "" at the location I disposal insert element elem: param I: specified location: param elem: inserted element elem: return: "" j = 0 p = self.L while j < iMui 1 and p is not None: # look up iMui 1 node j + = 1 p = p.next if p is None: # No logic found The node raise IndexError ("Index is out of range!") with the order of iMur1 Else: # find the node with logical bit order tmp = Node (elem) tmp.next = p.next p.next = tmp self.length + = 1 def delete (self) I): "" delete the element of the specified node: param I: specified node: return: deleted specified node element value "" if self.is_empty (): raise IndexError ("The list is empty!") Elif 0 < I

Tags: Nodes linearity structure storage location elements knowledge articles language logic order content length difference big code most that is more knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft vpn Apple Linux