"write a function that will concatenate two circular linked list producing one circular linked list" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "write a function that will concatenate two circular linked list producing one circular linked list" answered properly. Developers are finding an appropriate answer about write a function that will concatenate two circular linked list producing one circular linked list related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like write a function that will concatenate two circular linked list producing one circular linked list. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on write a function that will concatenate two circular linked list producing one circular linked list.
write a function that will concatenate two circular linked list producing one circular linked list
#include <stdio.h>
#include <stdlib.h>
struct node {
int data;
struct node *next;
};
struct node *even = NULL;
struct node *odd = NULL;
struct node *list = NULL;
//Create Linked List
void insert(int data) {
// Allocate memory for new node;
struct node *link = (struct node*) malloc(sizeof(struct node));
struct node *current;
link->data = data;
link->next = NULL;
if(data%2 == 0) {
if(even == NULL) {
even = link;
even->next = link;
return;
} else {
current = even;
while(current->next != even)
current = current->next;
// Insert link at the end of the list
current->next = link;
link->next = even;
}
} else {
if(odd == NULL) {
odd = link;
odd->next = link;
return;
} else {
current = odd;
while(current->next != odd) {
current = current->next;
}
// Insert link at the end of the list
current->next = link;
link->next = odd;
}
}
}
void display(struct node *head) {
int temp;
struct node *ptr = head;
if(head == NULL) {
printf("Linked List not initialized");
return;
} else if(head->next == head) {
printf("%d", head->data);
return;
}
printf("[head] =>");
while(ptr->next != head) {
printf(" %d =>",ptr->data);
ptr = ptr->next;
}
printf(" %d =>",ptr->data);
printf(" [head]\n");
}
void combine() {
struct node *elink, *olink;
list = even;
elink = list;
while(elink->next!= even) {
elink = elink->next;
}
elink->next = odd;
olink = odd;
while(olink->next!= odd) {
olink = olink->next;
}
olink->next = even;
}
int main() {
int i;
for(i = 1; i <= 10; i++)
insert(i);
printf("Even : ");
display(even);
printf("Odd : ");
display(odd);
combine();
printf("Combined List :\n");
display(list);
return 0;
}
Source: www.tutorialspoint.com
All those coders who are working on the Whatever based application and are stuck on write a function that will concatenate two circular linked list producing one circular linked list can get a collection of related answers to their query. Programmers need to enter their query on write a function that will concatenate two circular linked list producing one circular linked list related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about write a function that will concatenate two circular linked list producing one circular linked list for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of write a function that will concatenate two circular linked list producing one circular linked list while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "write a function that will concatenate two circular linked list producing one circular linked list". Visit this developer's friendly online web community, CodeProZone, and get your queries like write a function that will concatenate two circular linked list producing one circular linked list resolved professionally and stay updated to the latest Whatever updates.