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!
code:-
#include <stdio.h>
#include <stdlib.h>
//declarinf structure for Linked list
struct node
{
struct node *next,*prev;
int n;
}*h,*temp,*temp1,*temp2,*temp4;
int count = 0;
int main()
{
int ch;
h = NULL;
temp = temp1 = NULL;
int data,x;
//constructing single linked list
printf("Enter number of nodes:");
scanf("%d",&x);
temp =(struct node *)malloc(1*sizeof(struct
node));//creating head node
printf("\n Enter value to
node : ");
scanf("%d", &data);
temp->n = data;
temp->next = NULL;
h=temp;
//creating remaining nodes for linked list
for(int i=1;i<x;i++){
temp1 =(struct node
*)malloc(1*sizeof(struct node));
printf("\n Enter value to
node : ");
scanf("%d", &data);
temp1->n = data;
temp1->next = NULL;
temp->next = temp1;
temp=temp1;
}
//printing normal single linked list
temp = h;
if (temp == NULL)
{
printf("List empty to
display \n");
return 0;
}
printf("\nSingle Linked list elements from
begining : \n");
while (temp->next != NULL)
{
printf(" %d ",
temp->n);
temp =
temp->next;
}
printf(" %d ", temp->n);
//converting Single linked list into double
linked list
temp = h;
temp->prev=NULL;
while (temp->next != NULL)
{
temp1=temp;
temp =
temp->next;
temp->prev=temp1;
}
printf("\ndouble Linked list elements from begining to
end : \n");
temp = h;
while (temp->next != NULL)
{
printf(" %d ",
temp->n);
temp =
temp->next;
}
printf(" %d ", temp->n);
printf("\ndouble Linked list elements from end
to begining: \n");
while (temp->prev != NULL)
{
printf(" %d ",
temp->n);
temp =
temp->prev;
}
printf(" %d ", temp->n);
return 0;
}
output:

Thank you
Write a C function that iterates through a singly linked list and converts it to a...
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...
Write a Java class myLinkedList to simulate a singly linked list using arrays as the underlying structure. Include the following methods: 1. insert an element within the linked list.(this should also work for the front and the rear of the list) 2. Remove an element from the linked list 3. Display (print) the elements of the linked list in order. 4. A method to check if the list is "empty". Test your solution using a linked list that initially has...
java
singly linked list write a routine, which will travel through the list second and third list by taking every 2nd node from the first list and 3rd node Given a pointer to creating from the first list and putting them into the two newly created lists. (For example: If the original list had 12 nodes it should remain with nodes 1, 4, 7, and 10. The 2nd list would be made up of nodes 2, 5, 8, and 11...
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...
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...
Programing C Just with #include <stdio.h> We will create a singly linked list of 7 nodes. Then, the user will tell us whether to print the “odd-placed” nodes or the “even-placed” nodes. For example, if I had a list of 5 nodes like below, and the user specifies for the odd nodes to be printed, my program would print the values in nodes nl and n3. If the user instead indicated for the even nodes to be printed, my program...
***CODE MUST BE IN C++*** Using the linked list in "basic linked list" which has a STRUCTURE for each node, write FUNCTION which starts at the head and outputs the value for each node until the last node is reached. Note: your function should work with the structure that is in this program. Please do not use the example which is for a class, but this example canbe helkpful. Also note that the function must work no matter how many nodes...
C LINKED LIST #include <stdlib.h> #include <stdio.h> //Struct for a polynomial term (double linked list object) typedef struct Polynomial t_Polynomial; typedef struct Term { // coefficient of the polynomial term associated with the object int coef; // power of the polynomial term associated with the object int power; // pointer to the next object (to facilitate a doubly linked list) struct Term *next; // pointer to the previous object (to facilitate a doubly linked list) struct Term...