JAVA code for above problem-
import java.util.*;
class Create_second_third_list{
public static void formlists(LinkedList<Integer> str1)
{
//creating second and third linked list
LinkedList<Integer> str2 = new
LinkedList<Integer>();
LinkedList<Integer> str3 = new
LinkedList<Integer>();
int k=1; // counter for getting every second and third node
for(int num=0; num<str1.size();)
{
if(k==2){ // inserting every 2nd node in 2nd
list
str2.add(str1.get(num));
str1.remove(num);
k++;
}
else if(k==3){ // inserting every 3rd node in 3rd
list
str3.add(str1.get(num));
str1.remove(num);
k=1;
}
else{ // keeping the rest nodes in 1st list
k++;
num++;
}
}
System.out.println();
//displaying 1st list
System.out.print("First Linked List- ");
for(int num=0; num<str1.size(); num++)
{
System.out.print(str1.get(num)+" ");
}
System.out.println();
//displaying 2nd list
System.out.print("Second Linked List- ");
for(int num=0; num<str2.size(); num++)
{
System.out.print(str2.get(num)+" ");
}
System.out.println();
//displaying 3rd list
System.out.print("Third Linked List- ");
for(int num=0; num<str3.size(); num++)
{
System.out.print(str3.get(num)+" ");
}
System.out.println();
}
}
class Main {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
System.out.print("Enter the number of node in first linked
list-");
int n=scnr.nextInt(); // taking input 'n'
LinkedList<Integer> str1 = new
LinkedList<Integer>();
for(int i=1;i<=n;i++){ // inserting 1 to n in first list
str1.add(i); // creating the first linked list
}
// creating the object
Create_second_third_list C= new Create_second_third_list();
// calling the method
C.formlists(str1);
}
}
Code-




Input and Output-

If the answer helped then please upvote.And for any queries,please comment.
java singly linked list write a routine, which will travel through the list second and third...
2
Given a pointer to a singly linked list write a routine, which will travel through t creating a second list by taking every 3nd node from the first list and putting it ir newly created list. (For example: If the original list had 12 nodes it should remai nodes 1, 2, 4, 5, 7, 8, 10 and 11 while the 2nd list would be made up of nodes 3, 6, 12. Briefly explain: A. The advantage of implementing a...
You are given a pointer to a singly linked list. The singly linked list has cycles due to a programming error. Write a C program to detect whether the linked list has cycles without storing all the pointers to the nodes. The function detect_cycles should return 1 when a cycle is found and 0 when there are no cycles. Your code should handle all corner cases carefully and should not cause segmentation fault. Figure shows various examples of cycles for...
Q.(1)Describe the algorithm and java implementation for the following operations A. Create a singly linked list L1 with 4 nodes. You can use insert operation to add nodes to the list. Each element represent an airport code (e.g. BOS, ATL, JFK, MSP, etc.). Display the list L1 after it is created. B. Given singly linked list L1, create another singly linked list L2 that contains the same elements but in the reverse order. Display the content of both L1 and...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
use python
In class, we've studied Singly-Linked Lists which are made of nodes that point at subsequent nodes. One of the biggest annoyances with Linked Lists is the difficulty of going backwards through a list (such as getting the previous node or traversing the list backwards). An intuitive solution to this inefficiency is the doubly-linked list, which adds pointers to previ- ous nodes. Doubly-Linked Lists are not very different from Singly-Linked Lists, but are far more common because they are...
Write a C function that iterates through a singly linked list and converts it to a doubly linked list. Your solution must NOT create a second list. You must come up with the appropriate parameters and return type. Note: the nodes in the singly linked list have a field for a previous pointer, but that field has not initially been set in any of the nodes. You must do this as part of your solution!
Arrays, Lists, Stacks and Queues: 1) Write C++ code to reverse a singly-linked list L using only a constant amount of additional storage and no recursion. Assume the list object has a head pointer _head and consists of Node objects; a Node object has a pointer Node* _next
Answer all questions
1- in circular singly linked list, previous pointer of the first node points to which node A. First node B. Itself C. null D. Last node 2- Which of the following is NOT an applications of linked lists? A. Implementation of stacks and queues B. Dynamic memory allocation C. Manipulation of polynomials D. Keeping people at home during epidemics like corona virus 3- In a circular singly linked list? A. Components are all linked together in some...
Given the following linked list structure called node: struct node { int val; struct node * ptrNext; }; Assume we have a single list created from this structure with a head pointer called ptrFirst which is declared in the global scope. a. Write a complete C function called CountEven to count all the even values in this singly linked list of arbitrary number of nodes using an iterative (non-recursive) approach. The function takes as parameter the pointer to the starting...