Mục lục bài viết
Thủ Thuật về Splitting linked list C Chi Tiết
Update: 2021-12-31 18:31:52,Bạn Cần tương hỗ về Splitting linked list C. Bạn trọn vẹn có thể lại Comment ở phía dưới để Admin đc lý giải rõ ràng hơn.
Split single linked list into two halves
Write a C Program to Split single linked list into two halves.Heres simple Program to Split single linked list into two halves in C Programming Language.
Tóm lược đại ý quan trọng trong bài
- Split single linked list into two halves
- What is Linked List ?
- SOURCE CODE : :
What is Linked List ?
Linked list is a linear data structure that contains sequence of elements such that each element links to its next element in the sequence. Each link contains a connection to another link.
Following are the important terms to understand the concept of Linked List.
- Link Each link of a linked list can store a data called an element.
- Next Each link of a linked list contains a link to the next link called Next.
Each element in a linked list is called as Node. Each node consists of its own data and the address of the next node and forms a chain. Linked Lists are used to create trees and graphs.
Below is the source code for C Program to Split single linked list into two halves which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C Program to Split single linked list into two halves */
#include
#include
struct node
int info;
struct node *link;
;
struct node *create_list(struct node *start);
void display(struct node *start);
struct node *addatbeg(struct node *start,int data);
struct node *addatend(struct node *start,int data);
int Split(struct node *start, struct node **start1);
int main()
struct node *start=NULL,*start1=NULL;
int value;
start=create_list(start);
display(start);
if(start!=NULL)
Split(start, &start1);
display(start);
display(start1);
return 0;
/*End of main()*/
int Split(struct node *start, struct node **start1)
struct node *slow, *fast;
if(start->link==NULL) /*only one element*/
return 0;
slow=fast=start;
while(fast->link!=NULL && fast->link->link!=NULL)
slow = slow->link;
fast = fast->link->link;
*start1 = slow->link;
slow->link = NULL;
/*End of Split()*/
struct node *create_list(struct node *start)
int i,n,data;
printf(“Enter the number of nodes : “);
scanf(“%d”,&n);
start=NULL;
if(n==0)
return start;
printf(“nEnter the element to be inserted : “);
scanf(“%d”,&data);
start=addatbeg(start,data);
for(i=2;iinfo);
p.=p.->link;
printf(“nn”);
/*End of display() */
struct node *addatbeg(struct node *start,int data)
struct node *tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
tmp->link=start;
start=tmp;
return start;
/*End of addatbeg()*/
struct node *addatend(struct node *start,int data)
struct node *p.,*tmp;
tmp=(struct node *)malloc(sizeof(struct node));
tmp->info=data;
p.=start;
while(p.->link!=NULL)
p.=p.->link;
p.->link=tmp;
tmp->link=NULL;
return start;
/*End of addatend()*/
OUTPUT : :
/* C Program to Split single linked list into two halves */
************** OUTPUT ****************
Enter the number of nodes : 8
Enter the element to be inserted : 1
Enter the element to be inserted : 2
Enter the element to be inserted : 3
Enter the element to be inserted : 4
Enter the element to be inserted : 5
Enter the element to be inserted : 6
Enter the element to be inserted : 7
Enter the element to be inserted : 8
List is :
1 2 3 4 5 6 7 8
List is :
1 2 3 4
List is :
5 6 7 8
If you found any error or any queries related to the above program or any questions or reviews , you wanna to ask from us ,you may Contact Us through our contact Page or you can also comment below in the comment section.We will try our best to reach up to you in short interval.
Thanks for reading the post.
2.5 2 votesArticle RatingRelated posts:
Reply
7
0
Chia sẻ
Video full hướng dẫn Chia Sẻ Link Down Splitting linked list C ?
– Một số Keywords tìm kiếm nhiều : ” Review Splitting linked list C tiên tiến và phát triển nhất , Share Link Cập nhật Splitting linked list C “.
Giải đáp vướng mắc về Splitting linked list C
Quý quý khách trọn vẹn có thể để lại Comments nếu gặp yếu tố chưa hiểu nghen.
#Splitting #linked #list
Bình luận gần đây