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())