c語言循環拆分成和,C語言拆分循環鏈表程序

創建一個循環鏈表,并將這個循環鏈表拆分成為兩個循環鏈表的示例程序,將以下代碼保存到一個源文件中:split_circular_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 (list == NULL) { list = link; list->next = link; return; } current = list; while (current->next != list) current = current->next; // Insert link at the end of the list current->next = link; link->next = list; } void display(struct node *head) { struct node *ptr = head; printf("[head] =>"); //start from the beginning while (ptr->next != head) { printf(" %d =>", ptr->data); ptr = ptr->next; } printf(" %d =>", ptr->data); printf(" [head]n"); } void split_list() { int count = 0; // Allocate memory for new node; struct node *list1; struct node *link; struct node *current; list1 = list; while (list1->next != list) { struct node *link = (struct node*) malloc(sizeof(struct node)); link->data = list1->data; link->next = NULL; if (list1->data % 2 == 0) { if (even == NULL) { even = link; even->next = link; list1 = list1->next; continue; } else { current = even; while (current->next != even) { current = current->next; } // Insert link at the end of the list current->next = link; link->next = even; } list1 = list1->next; } else { if (odd == NULL) { odd = link; odd->next = link; list1 = list1->next; continue; } else { current = odd; while (current->next != odd) { current = current->next; } // Insert link at the end of the list current->next = link; link->next = odd; } list1 = list1->next; } } // Lets handle the last node link = (struct node*) malloc(sizeof(struct node)); link->data = list1->data; link->next = NULL; if (list1->data % 2 == 0) { current = even; while (current->next != even) { current = current->next; } // Insert link at the end of the list current->next = link; link->next = even; } else { current = odd; while (current->next != odd) { current = current->next; } // Insert link at the end of the list current->next = link; link->next = odd; } } int main() { int i; for (i = 1; i <= 10; i++) insert(i); printf("Complete list: n"); display(list); split_list(); printf("nOdd : "); display(odd); printf("Even : "); display(even); return 0; }

執行上面程序,得到以下結果 –

Complete list: [head] => 1 => 2 => 3 => 4 => 5 => 6 => 7 => 8 => 9 => 10 => [head] Odd : [head] => 1 => 3 => 5 => 7 => 9 => [head] Even : [head] => 2 => 4 => 6 => 8 => 10 => [head]

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/382940.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/382940.shtml
英文地址,請注明出處:http://en.pswp.cn/news/382940.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

pic單片機c語言讀eeprom,PIC16F877單片機內部EEPROM讀寫實例

;PIC16F877單片機內部EEPROM讀寫實例****************************************************************************************; This is a program to test the function of reading&writting for EEPROM.; YouCANOBServe the value of register(30H--?) buy changin…

C語言運行gis空間疊加分析,GIS空間疊加分析與緩沖區分析.doc

《地理信息系統》報告專 業 資源環境與城鄉規劃管理 姓 名 成 績班 級 學 號 日 期 2014/6/20目錄TOC \o "1-2" \h \u 14469 一、題目 23290 二、設計目的27200 三、設計背景2四、設計內容27200 四、步驟與過程27200 五、專題地圖 37521 四、總結分析 9題目佛山市順德…

組件文件已損壞或android內部模塊,android - Android Q更新后,模塊化系統組件在托管配置文件中不可用 - 堆棧內存溢出...

在從工作配置文件配置的設備設置應用中將操作系統從Android 9升級到10后&#xff0c;請停止運行。java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.settings/com.android.settings.applications.InstalledAppDetailsTop}: java.lang.NullPoin…

android文本復制自定義剪切板,android 剪切板-文本復制、粘貼

1. 粘貼&#xff0d;文本保存到剪切板中ClipboardManager clipboardManager (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);//創建ClipData對象ClipData clipData ClipData.newPlainText("orderNo", txt);//添加ClipData對象到剪切板中…

android保持服務不休眠,Android開發保持屏幕常亮和CPU不休眠喚醒狀態

安卓手機 APP 開發&#xff0c;有的時候需要屏幕長時間亮著&#xff0c;也就是不鎖屏&#xff0c;這時CPU會一直處于不休眠喚醒狀態。下面介紹兩種方法。方法一&#xff1a;通過 PowerManager 實現。此種方法會在軟件安裝時用戶可以看到屏幕選項。首先&#xff0c;在 AndroidMa…

android 磁場傳感器 羅盤,Android開發獲取重力加速度和磁場強度的方法

本文實例講述了Android開發獲取重力加速度和磁場強度的方法。分享給大家供大家參考&#xff0c;具體如下&#xff1a;Android獲取重力加速度和磁場強度主要依靠&#xff1a;Sensor.getRotationMatrix (float[] R, float[] I, float[] gravity, float[] geomagnetic)輸入數據&am…

android spinner位置,在Android中的Spinner中沒有選擇位置0

我創建了一個有三個項目的微調器日常每周每月一次我在我的java文件中執行了以下操作&#xff1a;navSpinner new ArrayList();navSpinner.add(new SpinnerNavItem(getResources().getString(R.string.dailyview)));navSpinner.add(new SpinnerNavItem(getResources().getStrin…

android tombstone發生過程,Android Tombstone解決步驟

這周和同事一起解了個tombstone的bug, 記錄下分析的過程&#xff0c;免得以后又忘記。。。1>log的分析pid: 122, tid: 14745, name: Binder_2 >>> /system/bin/mediaserver <<<signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000058eax 00000…

優酷android手機客戶端for,優酷手機客戶端

優酷手機客戶端官方最新版是官方出品的最新版播放軟件&#xff0c;該軟件上面匯聚了其他視頻app上沒有的精彩節目&#xff0c;全國各大精彩劇集與電影免費首播&#xff0c;更有獨特高清藍光畫質播放&#xff0c;想要體驗的朋友可以來欣賞一下!軟件特點1、高清流暢播放2、國內外…

html在線編輯器 asp.net,ASP.NET網站使用Kindeditor富文本編輯器配置步驟

1. 下載編輯器下載 KindEditor 最新版本&#xff0c;下載頁面: http://www.kindsoft.net/down.php2. 部署編輯器解壓 kindeditor-x.x.x.zip 文件&#xff0c;將editor文件夾復制到web目錄下3、在網頁中加入(ValidateRequest"false")4、引入腳本文件(XXX部分需要修改)…

html表格中綁定顯示xml文檔內容的簡單實例,JS讀取XML文件數據并以table形式顯示數據的方法(兼容IE與火狐)...

本文實例講述了JS讀取XML文件數據并以table形式顯示數據的方法。分享給大家供大家參考&#xff0c;具體如下&#xff1a;先看xml文件&#xff1a;張秋麗女 18李文才男 31李斯文男 22馬英女 25孫紅雷男 32歐陽俊雄男 28江琳女 23小小女 22aspx頁面代碼&#xff1a;function load…

html中通過定位 實現下拉,JS+CSS相對定位實現的下拉菜單

本文實例講述了JSCSS相對定位實現的下拉菜單。分享給大家供大家參考。具體如下&#xff1a;這里使用的是相對定位&#xff0c;不過效果還可以&#xff0c;用時候再修整一下&#xff0c;這個只是實現了大概功能&#xff0c;還有許多細節沒有修飾。運行效果截圖如下&#xff1a;在…

html頁面包含頭文件,Web前端技術:HTML部分---Head標簽中包含的頭文件標簽,body標簽包含的內部標簽...

1、Head標簽中包含的 頭文件標簽的作用&#xff1a;(1)title標簽&#xff1a;定義網頁的標題。(2)meta標簽&#xff1a;一般用于定義頁面的特殊信息&#xff0c;例如頁面的關鍵字、頁面描述等(3)link標簽&#xff1a;用于引入外部樣式文件(CSS 文件)。(4)style標簽&#xff1a;…

爬蟲圖片href是html圖片,xpath爬蟲實例,爬取圖片網站百度盤地址和提取碼

某套圖網站&#xff0c;套圖以封面形式展現在頁面&#xff0c;需要依次點擊套圖&#xff0c;點擊廣告盤鏈接&#xff0c;最后到達百度網盤展示頁面。這一過程通過爬蟲來實現&#xff0c;收集百度網盤地址和提取碼&#xff0c;采用xpath爬蟲技術1、首先分析圖片列表頁&#xff0…

HTML如何做個播放器圖表,Web繪圖神器之ECharts-ts文件播放器

前言最近在做一個項目需要用到大量的圖形報表來展示數據。就去對比了一些前端圖形報表框架&#xff0c;有Highcharts、Echarts、Three.js。發現Three.js比較笨重&#xff0c;不太適合數據展示&#xff0c;做前端動畫還是比較好。而highcharts、echarts比較輕量級拿來就用比較方…

微型計算機主存可以分為,計算機基礎試題 (含答案)

計算機基礎試題 (含答案)一、填空題(每空1分&#xff0c;共30分)1、計算計的軟件系統通常分成______軟件和______軟件。2、字長是計算機______次能處理的______進制位數。3、1KB______B;1MB______KB。4、計算機中&#xff0c;中央處理器CPU由______和______兩部分組成。5、CPU按…

90年代微型計算機,版本控制如何在80年代和90年代的當今微型計算機上工作?

您必須在當時的通用基礎結構中看到這一點。在80年代初期&#xff0c;IBM發布了“個人計算機”&#xff0c;您可以從字面上理解它。開發PC應用程序的最常見方法是一個人創建某些東西并試圖出售它。因此&#xff0c;每個發行版本一張軟盤可能很常見。您可以購買一些漂亮的彩色標簽…

全國英語計算機9月統考2019,2019年9月網絡教育統考《計算機應用基礎》模擬題6...

本文為大家提供2019年9月網絡教育統考《計算機應用基礎》模擬題6&#xff0c;有需要的考生請自取。網絡教育本科全國統考《計算機應用基礎》模擬題6一、單選題1、第一臺電子數字計算機誕生于 ______。A &#xff1a; 麻省理工學院B &#xff1a; 哈佛大學C &#xff1a; 賓夕法…

計算機網絡原碼反碼補碼,計算機的原碼和反碼及補碼到底是什么

數據在計算機里面都是以0和1存儲和運算的&#xff0c;這是馮諾依曼體系的基礎。比如一個數在計算機中若有正負之分&#xff0c;則用一個數的最高位(符號位)用來表示它的正負&#xff0c;其中0表示正數&#xff0c;1表示負數。原碼就是整數絕對值的二進制形式&#xff0c;為了解…

計算機組裝活動口號,廣教育、多技能、求發展喜迎計算機系第五屆電腦文化節...

在深入學習實踐科學發展觀&#xff0c;改革教育教學模式&#xff0c;迎接高職院校人才培養評估工作的今天&#xff0c;為貫徹以人為本理念&#xff0c;全方位服務學生&#xff0c;培養學生綜合技能&#xff0c;本學期計算機系舉辦第五屆電腦文化節&#xff0c;舉辦電腦文化節是…