Computer Science, asked by Palani07, 2 months ago

Consider the below inputs:
input_linked_list (Head to Tail): 1 ->2 ->5 ->3
input_stack (Top to Bottom): 4, 2, 5, 10

def generate (input_linked_list , input_stack):
temp= input_linked_list.get_head ( )
element=0
while(temp.get_next ( ) is not None):
temp.set_data (temp.get_data ( )+temp.get_next ( ). get_data ( )+element)
if temp.get_data ( ) %2 !=0:
temp.set_data(temp.get_data ( ) +input_stack.pop ( ) )
element=temp.get_data ( )
else:
input_stack.push (element )
element=temp.get_next ( ).get_data ( )
temp=temp.get_next ( )
temp.set_data(temp.get_data ( )+input_stack.pop ( ) )

What will be the content of Input_linked_list from head to tail and input_stack from top to bottom after the execution of the function generate?

Assumption: Stack and LinkedList classes, with the necessary methods, are available
A:
input_linked_list (Head to Tail): 7 -> 14 -> 20 -> 5
input_stack (Top of Bottom): 5, 10

B:
input_linked_list (Head to Tail): 5 -> 7 -> 10 -> 5
input_stack (Top of Bottom): 2, 5, 10

C:
input_linked_list (Head to Tail): 7 -> 14 -> 20 -> 3
input_stack (Top of Bottom): 5, 10

D:
input_linked_list (Head to Tail): 7 -> 14 -> 20 -> 5
input_stack (Top of Bottom): 10

Answers

Answered by satwikdash2000
0

Answer:

C

Explanation:

Answered by sujan3006sl
0

Answer:

The appropriate response to the question is

Option B) input_linked_list        (Head to Tail): 5 -> 7 -> 10 -> 5

                 input_stack (Top of Bottom): 2, 5, 10

Explanation:

  • Every node is tested to see whether the values are multiples of 2, and if they are not, a value from the stack is popped and put to them, overwriting any prior values.

Approach: These are the actions to take:

  • From the centre, divide the list. divide your body in front and behind. If there are more than two components, the additional one should go in the first (front) list.
  • Reverse the second list (back).
  • While concurrently traversing both lists, do the necessary subtraction.
  • Invert the second list once more.
  • Add the last item from the second list to the end of the first list.

#SPJ2

Similar questions