日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

c语言 如何连接两个程序,C语言连接两个链表程序

發(fā)布時間:2023/12/10 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言 如何连接两个程序,C语言连接两个链表程序 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

創(chuàng)建兩個鏈表,并這兩鏈表連接起來成為一個鏈表的示例程序,將以下代碼保存到一個源文件中:combine_linked_list.c, 如下所示 –

#include #include 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; return; } else { current = even; while (current->next != NULL) current = current->next; // Insert link at the end of the list current->next = link; } } else { if (odd == NULL) { odd = link; return; } else { current = odd; while (current->next != NULL) current = current->next; // Insert link at the end of the list current->next = link; } } } void display(struct node *head) { struct node *ptr = head; printf("[head] =>"); while (ptr != NULL) { printf(" %d =>", ptr->data); ptr = ptr->next; } printf(" [null]n"); } void combine() { struct node *link; list = even; link = list; while (link->next != NULL) { link = link->next; } link->next = odd; } 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; }

執(zhí)行上面程序,得到以下結果 –

Even : [head] => 2 => 4 => 6 => 8 => 10 => [null] Odd : [head] => 1 => 3 => 5 => 7 => 9 => [null] Combined List : [head] => 2 => 4 => 6 => 8 => 10 => 1 => 3 => 5 => 7 => 9 => [null]

¥ 我要打賞 糾錯/補充 收藏

總結

以上是生活随笔為你收集整理的c语言 如何连接两个程序,C语言连接两个链表程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。