JavaScript Program to Print all Odd Elements in a Sorted Order of a Linked List Last Updated : 29 Feb, 2024 Comments Improve Suggest changes Like Article Like Report This JavaScript program aims to print all odd elements in a sorted order of a linked list. A linked list is a data structure consisting of a sequence of elements, where each element points to the next element in the sequence. The program traverses the linked list and prints all odd elements in a sorted order of a linked list Table of Content Iterative ApproachRecursive ApproachIterative ApproachThe elements of the linked list are traversed using a loop and each one of them is checked for the odd value. It prints the odd values on the console. Example: The below example prints odd numbers in a linked list in JavaScript. JavaScript class Node { constructor(value) { this.value = value; this.next = null; } } function createLinkedList(arr) { if (arr.length === 0) { return null; } let head = new Node(arr[0]); let current = head; for (let i = 1; i < arr.length; i++) { current.next = new Node(arr[i]); current = current.next; } return { head }; } function printOddNumbersIterative(head) { let current = head; while (current !== null) { if (current.value %2 !== 0) { console.log(current.value); } current = current.next; } } const linkedList = createLinkedList([1, 2, 3, 4, 5]); printOddNumbersIterative(linkedList.head); Output1 3 5 Recursive ApproachImplement a recursive function to traverse the linked list, checking each element recursively and printing the odd numbers encountered. Example: The below example is to print odd numbers in a linked list in JavaScript. JavaScript class Node { constructor(value) { this.value = value; this.next = null; } } function createLinkedList(arr) { if (arr.length === 0) { return null; } let head = new Node(arr[0]); let current = head; for (let i = 1; i < arr.length; i++) { current.next = new Node(arr[i]); current = current.next; } return { head }; } function printOddNumbersRecursive(node) { if (node === null) { return; } if (node.value %2 !== 0) { console.log(node.value); } printOddNumbersRecursive(node.next); } const linkedList = createLinkedList([1, 2, 3, 4, 5]); printOddNumbersRecursive(linkedList.head); Output: 135 Comment More infoAdvertise with us Next Article JavaScript Program to Print all Odd Elements in a Sorted Order of a Linked List A anjugaeu01 Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Program Similar Reads JavaScript Program to Print all Even Numbers in a Sorted Order of a Linked List This JavaScript program is designed to identify all even numbers in a sorted order of a linked list. A linked list is a linear data structure where elements, known as nodes, are connected via pointers. The program iterates through the linked list to determine the all-even numbers in the sorted order 3 min read JavaScript Program to Print Even Numbers in a Linked List A linked list is a data structure that stores the values at different memory locations concerning the next memory block of stored value. You can get all the even numbers stored in a linked list using the below methods. Table of Content Using While LoopUsing RecursionUsing While LoopTo print even num 2 min read JavaScript Program to Print Odd Numbers in a Linked List This article will show you different ways to find and print all the odd numbers in a linked list using JavaScript. Example: Input: 2->1->9->3 Output: 1, 9, 3 Input: 5->5->1->0->19->8 Output: 5, 5, 1, 19Table of Content Using Recursive ApproachUsing While LoopUsing For LoopUsi 4 min read Javascript Program For Arranging Single Linked List In Alternate Odd and Even Nodes Order Given a singly linked list, rearrange the list so that even and odd nodes are alternate in the list.There are two possible forms of this rearrangement. If the first data is odd, then the second node must be even. The third node must be odd and so on. Notice that another arrangement is possible where 7 min read Java Program to Return the Elements at Odd Positions in a List Given a List, the task is to return the elements at Odd positions in a list. Let's consider the following list.Clearly, we can see that elements 20, 40, 60 are at Odd Positions as the index of the list is zero-based. Now we should return these elements.Approach 1:Initialize a temporary value with ze 3 min read Javascript Program To Check Whether The Length Of Given Linked List Is Even Or Odd Given a linked list, the task is to make a function which checks whether the length of the linked list is even or odd. Examples:Input : 1->2->3->4->NULLOutput : EvenInput : 1->2->3->4->5->NULLOutput : OddMethod 1: Count the codes linearly Traverse the entire Linked List an 3 min read Java Program to Sort the Elements of the Circular Linked List In a circular linked list, every node points to its next node in the sequence but the last node points to the first node in the list. Here, Create a circular linked list and sort the circular linked list in ascending order. Circular linked list before sorting: CIRCULAR LINKED LIST Circular linked li 3 min read Javascript Program For Printing Reverse Of A Linked List Without Actually Reversing Given a linked list, print reverse of it using a recursive function. For example, if the given linked list is 1->2->3->4, then output should be 4->3->2->1.Note that the question is only about printing the reverse. To reverse the list itself see this Difficulty Level: Rookie Algorit 2 min read Java Program to Print the Elements of an Array Present on Odd Position An array stores the collection of data of the same type. It is a fixed-size sequential collection of elements of the same type. In an array, if there are "N" elements, the array iteration starts from 0 and ends with "N-1". The odd positions in the array are those with even indexing and vice versa. E 3 min read Java Program to Print the Elements of an Array Present on Even Position The task is to print all the elements that are present in even position. Consider an example, we have an array of length 6, and we need to display all the elements that are present in 2,4 and 6 positions i.e; at indices 1, 3, 5. Example: Input: [1,2,3,4,5,6] Output: 2 4 6 Input: [1,2] Output: 2 Appr 2 min read Like