Given a linked list with odd and even numbers, change the list in such a way that the even numbers appear first followed by the odd numbersDonot change the value.Sample Input:12 34 13 57 19 48 29 10 28 58 -1Sample Output:12 34 48 10 28 58 13 57 19 29
Question
Given a linked list with odd and even numbers, change the list in such a way that the even numbers appear first followed by the odd numbersDonot change the value.Sample Input:12 34 13 57 19 48 29 10 28 58 -1Sample Output:12 34 48 10 28 58 13 57 19 29
Solution
Sure, here is a Python solution for the problem:
class Node:
def __init__(self, data):
self.data = data
Similar Questions
Write a Python program that prompts the user to input a list of integers separated by commas. Your task is to modify the list so that all elements become odd by incrementing each even element by 1, and then print the modified list.Input format:The input consists of a list of integers separated by commas.Output format:Output the modified list where all elements are odd.Sample Test CasesTest Case 1:Expected Output:1,3,5,7[1,·3,·5,·7]Test Case 2:Expected Output:2,1,5,8[3,·1,·5,·9]
Alternate Elements in Linked ListYou are now well versed with the concepts of Linked Lists. So, now you have been given an advance coding challenge, i.e., you have to create the code on the topic linked lists such that it will give the output of only elements in alternate position from last to first and then first to last. Constraints:Input Format :First line of input contains the number of integers.Next lines are followed by the integer values.Output Format :Corresponding output.Example:Input 1:51 2 3 4 5Output 1:1 3 55 3 1 Input 2:411 12 14 13Output 2:12 1313 12 Explanation:Alternate elements from first element are 1 3 5Alternate elements from last to first are 5 3 1Public Test Cases:# INPUT EXPECTED OUTPUT1 51 2 3 4 51 3 5 5 3 1 2 4 11 12 14 1311 14 13 12
Define a function odd_numbers(n) with one argument integer n. The function find all odd numbers less than and equal to n and returns a list with all the odd numbers you found.Hintlist.append() is an inbuilt method in the Python to store an odd number into a list.
reverse a linked list- DATA STRUCTURESWrite a program to reverse a linked list.Constraints:Integers onlyExample:Input FormatTo get the number of elements followed by the elements separated by a single space.Output FormatDisplays the reversed list.Note: There is a space at the end of the outputExplanation:linked listPublic Test Cases:# INPUT EXPECTED OUTPUT1 3 67 45 1212 45 672 5 -1 3 2 6 44 6 2 3 -1
Question 3: Given a list of integers, please create a new list where each element is half of the even numbers in the original list.numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.