python 链表和递归的问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 链表和递归的问题相关的知识,希望对你有一定的参考价值。

#Linked List recursion practice

class Link:
	
	def __init__(self, value, next=None):
		self.value = value
		self.next = next
	
	def __repr__(self):
		return str(self.value) + "->(" + str(self.next) + ")"
		
		
		
#problem 1
#Implement a function that takes a string and uses recursion to make a linked list of characters, or 1 byte long strings. Hint use slice indexes on the string !
"""
x = "Hello world"
=> None
   charlist(x)
=> H->(e->(l->(l->(o->( ->(w->(o->(r->(l->(d->(None)))))))))))
"""

def charlist(string):
	pass
		
		
#problem 2
#implement a function that takes a linked list of characters and uses recursion to concat those characters back into a string.
"""
=> None
   x = "Hello world"
=> None
   f = charlist(x)
=> None
   lst_to_string(f)
=> 'Hello world'
"""

def lst_to_string(lst):
	pass

以上是关于python 链表和递归的问题的主要内容,如果未能解决你的问题,请参考以下文章

玩转数据结构:第5章 链表和递归

递归:一维链表和数组

玩转数据结构——链表和递归

c语言——链表和二叉树

链表和双指针框架

Python数据结构学习笔记——链表:无序链表和有序链表