zoukankan      html  css  js  c++  java
  • 剑指offer python版 从尾到头打印链表

    class ListNode(object):
        def __init__(self,x):
            self.val=x
            self.next=None
            
    class Link(object):
        def __init__(self,values=None):
            self.nodes=self.set_link(values) if  values else None
            
        def get_link(self):
            return self.nodes
        def set_link(self,values):
            if not values :
                return False
            head=ListNode(0)
            move=head
            
            
            try:
                for i in values:
                    tmp=ListNode(i)
                    move.next=tmp
                    move=move.next
                    
            except Exception as e:
                print(e)
                
            return head.next
        
        def print_link(self):
            head=self.nodes
            stack=[]
            ret=[]
            while head:
                stack.append(head.val)
                head=head.next
                
            while stack:
                ret.append(stack.pop())
                
            return ret
        
    a=Link([1,2,3,4,5])
    
    b=a.get_link()
    
    
    print(a.print_link())
  • 相关阅读:
    1069.查找学生信息
    1023.Excel排序
    1061.成绩排序
    bzoj 1113
    bzoj 1112 treap树
    bzoj 1225 dfs + 一点点数论
    bzoj 1224
    UESTC
    HDU 3530 单调队列
    bzoj 1233
  • 原文地址:https://www.cnblogs.com/xzm123/p/9847906.html
Copyright © 2011-2022 走看看