Question: Python pls Define python function lunar_i and lunar_j . These functions take two linked lists as arguments. This function returns the first element of each
Python pls
Define python function lunar_i and lunar_j . These functions take two linked lists as arguments. This function returns the first element of each linked list. If one list becomes empty, then another linked list will replace. For the result, all elements of two linked lists should appear in the result. The original linked lists are mutated by this function. The two different functions should return the same value if it's correct. However, one function should be an iterative function, and the other function should be a recursive function.
There are few restrictions when you create functions.
1. Do not create any python data structures, such as local variables, new class objects, other functions, etc..
2. YOU CAN ONLY USE LINKED PROCESSING
3. The function should be one iterative function, one recursive function

class Lunar: num = 0 def __init__(self,val,nx=None): self.val = val self.nx = nx LN.num += 1
def list_trans_a(a): if a == []: return None front = rear = Lunar(a[0]) for i in a[1:]: rear.nx = LN(i) rear = rear.nx return front
def str_result(aa): result = '' while aa != None: result += str(aa.val)+'->' aa = aa.nx return result + 'None'
#iterative function pls
def lunar_i(a:lunar,b:lunar) -> lunar:
pass
#Recursive function pls
def lunar_j(a:lunar,b:lunar) -> lunar:
pass
For example outputs
a2= list_trans_a(['a','b','c','d','e','f','g']) b2 = list_trans_a(['w','x','y','z'])
ab2 = lunar_i(a2,b2)
ab2j = lunar_j(a2,b2)
print(' alternate = ',str_result(ab2))
print(' alternate = ',str_result(ab2j))
should print
a->w->b->x->c->y->d->z->e->f->g->None
a->w->b->x->c->y->d->z->1->2->3->4->None
a3 = list_trans_a(['a','b','c','d']) b3 = list_trans_a(['w','x','y','z',1,2,3,4])
ab3 = lunar_i(a2,b2)
ab3j = lunar_j(a3,b3)
print(' alternate = ',str_result(ab3))
print(' alternate = ',str_result(ab3j))
should print
a->w->b->x->c->y->d->z->1->2->3->4->None
a->w->b->x->c->y->d->z->1->2->3->4->None
a0 = []
b0 = []
should print
None
None
class Lunar: num = 0 def __init_(self,val, nx=None): self.val = val self.nx LN.num += 1 = nx def list_trans_a(a): if a == []: return None front = rear = Lunar (a[0]) for i in a[1:]: rear.nx = LN(i) rear = rear.nx return front def str_result(aa): result = " while aa != None: result += str(aa.val)+'-> aa = aa.nx return result + 'None
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
