DAPP质押模式系统开发方案丨DAPP合约项目系统开发技术流程

简介: DAPP质押模式系统开发方案丨DAPP合约项目系统开发技术流程

单链表反转
唯一就是有一处笔误。
3.4.4 两个链表操作/链表反转 书中代码是:
def rev(self):

p = None
while self._head is not None:
    q = self._head
    self._head = q.next # 摘下原来的原结点
    q._next = p 
    p = q               # 将刚摘下的结点加入 p 引用的结点序列
self._head = p          # 反转后的结点序列已经做好,重置表头链接

其中倒数第三行的 ._next 应该改为 .next,因为结点类 LNode 中类属性是.next。

    q.next = p

如果把其中的 p 变量更名为 tmp_list_head,把 q 改为 sliced_node可能更能理解。
完整的程序,包括测试如下:

coding:utf8

class LinkedListUnderflow(ValueError):

pass

class LNode(object):

def __init__(self, elem, next_=None):
    self.elem = elem
    self.next = next_

class LList(object):

def __init__(self):
    self._head = None

def is_empty(self):
    return self._head is None

def prepend(self, elem):
    self._head = LNode(elem, self._head)

def pop(self):
    if self._head is None:
        raise LinkedListUnderflow("in pop")
    e = self._head.elem
    self._head = self._head.next
    return e

def append(self, elem):
    if self._head is None:
        self._head = LNode(elem)
        return
    p = self._head
    while p.next is not None:
        p = p.next
    p.next = LNode(elem)

def pop_last(self):
    if self._head is None:
        raise LinkedListUnderflow
    p = self._head
    if p.next is None:
        e = p.elem
        self._head = None
        return e
    while p.next.next is not None:
        p = p.next
    e = p.next.elem
    p.next = None
    return e

def rev(self):
    tmp_list_head = None
    while self._head is not None:
        sliced_node = self._head
        self._head = self._head.next
        sliced_node.next = tmp_list_head
        tmp_list_head = sliced_node 
    self._head = tmp_list_head

def elements(self):
    p = self._head
    while p is not None:
        yield p.elem
        p = p.next

def main():

lst = LList()
for i in range(10):
    lst.append(i)
print "original linked list:"
for i in lst.elements():
    print i

print '-' * 25
print "reserved linked list:"

lst.rev()
for i in lst.elements():
    print i 

if name == '__main__':

main()
相关文章
|
2月前
|
算法 大数据 分布式数据库
DAPP质押模式系统开发项目方案|DAPP合约开发案例
区块链技术是一种分布式数据库技术,它是由多个节点构成的去中心化网络
|
2月前
|
安全 区块链
dapp/defi智能合约质押分红系统开发详细功能/案例步骤/需求逻辑/源码指南
Developing a DApp/DeFi smart contract staking dividend system involves multiple technical and functional requirements. The following are possible detailed development steps and functional requirements for your reference
|
2月前
|
安全 区块链
DAPP模式系统开发设计方案丨DAPP合约系统开发技术方案
DAPP模式系统开发设计方案丨DAPP合约系统开发技术方案
|
2月前
|
安全 区块链
DAPP质押分红项目系统开发|逻辑原理
Web 3.0是一个新的网络技术,它将使用户能够利用区块链技术来访问数字内容
|
7月前
|
安全 区块链 数据安全/隐私保护
dapp质押模式系统开发案例需求
区块链智能合约是一种以代码形式编写的合约,可以自动执行和执行的合约
|
8月前
|
存储 算法 区块链
DAPP合约公排系统开发案例|DAPP互助系统开发
去中心化就是指网络中各个节点的地位相等,传输内容和交易数据不再需要通过某个中心节点进行
|
9月前
|
存储 安全 区块链
DAPP互助合约系统开发功能逻辑说明
DApp互助系统的开发指的是创建一个基于区块链技术和智能合约的去中心化应用程序(DApp),旨在通过互助和合作实现共同利益和社区发展。
|
10月前
|
存储 算法 区块链
DAPP智能合约系统软件开发案例 | 币安智能链模式系统开发
币安链和其它许多项目类似,比如EOS。它具有高吞吐量和高性能的底层匹配引擎,可以同时迅速的支持和处理大量交易。但是不够灵活性,无法支持许多复杂的DAPP。
|
11月前
|
存储 监控 算法
DAPP链上质押项目系统开发|DAPP合约模式开发案例
DAPP不依赖中心化机构也不受单一实体控制,因此DAPP可以减少中心化机构的意见干扰