jweinst1
10/12/2016 - 4:41 PM

questions for linked lists and recursions

questions for linked lists and recursions

#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