![post-title](https://i.ytimg.com/vi/_RsaNzZFuUU/hqdefault.jpg)
linked list c範例 在 コバにゃんチャンネル Youtube 的最佳解答
![post-title](https://i.ytimg.com/vi/_RsaNzZFuUU/hqdefault.jpg)
Search
Linked list. (完整範例程式碼也可以看這裡:Linkedlist.cpp). class ListNode 與 class LinkedList 的定義如下:. // C++ code #include <iostream> using std::cout; ... ... <看更多>
真是磨人的妖孽。還有比Linked list更難的部分嗎?有沒有卦!--推frommr: hello world 01/04 14:52→ linceass: 摸到C罩杯01/04 14:52→ PONANZA: 罩杯01/04 14:52噓 c. ... <看更多>
#1. C語言鏈結串列(link list)的實作範例 - 讀處- 痞客邦
鏈結串列(link list)是由節點(node)串接而成而每個節點是採動態記憶體配置的方式來配置記憶體給他們節點包含2個成員,第一個是該節點所儲存的資料第二 ...
#2. C 語言:鏈結串列(Linked List)的建立與刪除 - 寫點科普Kopuchat
要怎麼在陣列中指定位置插入或刪除資料呢?鏈結串列這個小幫手就應運而生了噢!它把Array 的值拆成好幾個節點,各節點之間並不一定占用連續的記憶體 ...
#3. 你所不知道的C 語言: linked list 和非連續記憶體 - HackMD
檢驗學員對於C 語言指標操作的熟悉程度; linked list ((鏈結串列) 本質上就是對非 ... 核心、C 語言函式庫內部、程式開發框架,到應用程式,都不難見到linked list 的 ...
#4. [資料結構] 使用C 語言:實作鏈結串列(Linked List) - 開源教學
如同我們先前實作佇列般,串列分為內部節點 Node 和主類別 List 。等效的C 語言宣告如下:. typedef struct node node_t; struct node { int data; node_t *prev; ...
#5. [資料結構] 鏈結串列教學[1]: 新增與印出 - Medium
2020年2月14日 — 鏈結串列,英文為linked list,是一種資料結構結構型態,我們可以藉由鏈結串列把資料一個一個串在一起,相較於陣列有著更彈性的增減數據的方式。
Linked list. (完整範例程式碼也可以看這裡:Linkedlist.cpp). class ListNode 與 class LinkedList 的定義如下:. // C++ code #include <iostream> using std::cout; ...
程式碼. 以下範例是自行設定node 的數量以及每一個node 內的data 值。
#8. 陣列與鏈結串列Array and Linked List
node c; node *head; c.next = NULL; head = NULL; head = new node; ... 範例:print() ... node *LinkedList::getnode () /* 此函數產生一個新節點*/.
#9. [C/C++] 鏈結串列(Linked List) - WordPress.com
[C/C++] 鏈結串列(Linked List). Wuzz C/C++,Programming 21 九月, ... 完整程式碼範例: ... 以下準備把linked list裡面的東西都印出來.
#10. C語言系列: 以鏈結串列實現成績管理程式| 閱讀的城市貓 - - 點部落
2020年1月29日 — 複習Linked List,並以此來實現成績管理程式的存檔、讀檔、自動排序、新增、刪除、修改成績功能。
#11. 最簡單的linked list 範例! | Better life with Ubuntu
基本linked list 範例,鍊結串練範例! ... #include #include #include struct list{ int no; char cont[50]; struct list* next ... gcc -Wall ll.c.
#12. Day-19 ADT與鏈結串列(linked list) - iT 邦幫忙
以C語言為例,一般來說會將含是ㄓ也就是.h檔案中,具體節點(Node)的宣告則放在.c檔案中,下面示範為鏈結串列的ADT。 #ifndef _List_H struct Node; typedef struct Node * ...
#13. 單向鏈結串列(Single Linked List)
資料結構中單向鏈結串列(Single Linked List)的介紹. ... Reverse Linked List:串列反轉. 將串列節點的順序顛倒. C++. struct Node* reverse(struct Node** List){ ...
#14. 【演算】連結串列- Linked List - Infinite Loop
假設現在我們要將A 與C 節點中的B 節點移除,則將A 節點的連結指標指向C 即可。 以上兩種操作的虛擬碼大致如下: void insert(Node* n1, Node* n2) { ...
#15. Chapter 3 鏈結串列結構資料結構導論- C語言實作. - SlidePlayer
3.1 前言陣列結構(Array)和鏈結串列(Linked List): 陣列的使用是透過陣列變數及對應的索引來存取陣列個別元素。 鏈結串列儲存資料的方式是將個別資料項次(data item) ...
#16. C 語言初學教材- 第六章鏈結串列
C 語言初學教材- 第六章鏈結串列. 我們已經有了記錄單筆通訊錄資料的結構 friendData ,現在需要考慮如何進行多筆資料的處理。只使用變數可以嗎?可以的,但是比須先 ...
#17. 練習5-刪除前端節點請將下方(1)鏈結串列
C Language. 4. 動態記憶體配置---malloc函數. 範例:. #include<stdio.h>. int main() ... Link. 單向鏈結串列的節點結構. CSIM, PU. C Language. 7. 單向鏈結串列.
#18. 單向鏈結串列Singly linked list
和C++ 的RAII 一樣,Rust 有一個名叫 drop 的解構式,只要程式執行離開了資源擁有者的可視範圍(out of scope),就會自動呼叫 drop 。我們在Drop trait 一節會再深入探討 ...
#19. 鏈結串列:內含物件版| 高等C語言
程式範例:鏈結串列-- 內含物件版 ... node->next = list->head; list->head = node; } typedef void(*F1)(void*); void ListPrint(List *list, F1 f) { ListNode *p; ...
#20. C++ linked list 簡單範例 - 好人超的第五個窩
C++ linked list 簡單範例 ... 讀取這個檔案內容,並放至linked-list 裡,可以這樣做:. #include <iostream> #include <fstream>
#21. 陣列與鏈結串列Array and Linked List - PDF Free Download
陣列與鏈結串列Array and Linked List 講師: 洪安1 大綱結構陣列鏈結串列單向鏈結串 ... 指標直到存取到NULL 為止範例:print() 走訪鏈結串列並輸出每個節點之data 值14.
#22. Learn How to Use a Linked List C++ With A Handy Guide
There are two types of linked lists: a singly-linked list and a doubly-linked list. The singly-linked list contains nodes that only point to the ...
#23. 鏈結串列- 維基百科,自由的百科全書
像Lisp和Scheme這樣的語言的內建資料類型中就包含了鏈結串列的存取和操作。程式語言或物件導向語言,如C/C++和Java依靠易變工具來生成鏈結串列。 目次.
#24. 資料結構
使用書籍:資料結構C語言實作(Fundamentals of Data Structures), 陳惠貞, 碁峰資訊股份有限公司. Chapter 01 導論; Chapter 02 陣列; Chapter 03 鏈結串列 ...
#25. C語言資料結構鏈結串列(Linked list) 程式碼一份程式 ... - 露天拍賣
你在找的C語言資料結構鏈結串列(Linked list) 程式碼一份程式語言程式設計就在露天拍賣,立即購買商品搶免運及優惠,還有許多相關商品提供瀏覽.
#26. 詳解雙向連結串列的基本操作(C語言) | IT人
這裡給出建立雙向連結串列的C 語言實現程式碼: ... 加上以下兩句就是雙向迴圈連結串列*/ // list->next=head; // head->prior=list; return head; } ...
#27. 真的很可怕的C語言ch15--動態記憶體讀書筆記
我們可以把memory.c這個範例程式改造,利用calloc()來確保記憶體。 ... 我們來介紹linked list作為動態記憶體的使用方式的例子。
#28. [C語言] 以鏈結串列(Linked List) 實作資料結構的佇列(Queue)
[C語言] 以鏈結串列(Linked List) 實作資料結構的佇列(Queue). Linked List implementation of queue. 佇列(Queue)稱為FIFO (First In First Out)的 ...
#29. C說話鏈結串列(link list)的實作範例@ chambeeac08@outlook ...
C 說話鏈結串列(link list)的實作範例 · 上述典範榜樣是以靜態的體式格局來設置裝備擺設, · 這類配置體式格局會有些未便,例如在新增節點,同時當一個節點不 ...
#30. 二、用C 語言撰寫一個函式,能將一只含有數字的單向鏈結串列 ...
【非選題】 二、用C 語言撰寫一個函式,能將一只含有數字的單向鏈結串列(singly linked list)切割成兩個單向鏈結串列,其一只包含奇數元素,另一只包含偶數元素,請 ...
#31. Linked List | Set 1 (Introduction) - GeeksforGeeks
1) data (we can store integer, strings or any type of data). ... In C, we can represent a node using structures. Below is an example of a linked ...
#32. 206. Reverse Linked List(c語言) - 台部落
Reverse Linked List(c語言). 原創 asheroly 2020-05-30 23:29. 測試面試必考的反轉鏈表. /** * Definition for singly-linked list. * struct ListNode { * int val; ...
#33. 迴圈連結串列 - tw511教學網
Singly Linked List as Circular Linked List ... int data){ //create a link struct node *link = (struct node*) ... 要看到它在C語言程式設計實現,請點選 。
#34. <C語言> Stack By Array And Linked List - 資料結構 - Bear Duen
<C語言> Stack By Array And Linked List - 資料結構 · Stack的概念 · 想像有一個容器,我們依序放入東西進去,當要拿出東西時,一定是先取出最後放進去的 ...
#35. [C語言] 連結串列(link list) - Jax 的工作紀錄
[C語言] 連結串列(link list) ... struct link_node *link; } LINK_NODE; /* 產生新節點*/ ... LINK_NODE *push_node(LINK_NODE *list, int data){
#36. C範例程式: 鍊結串列linked list - Jengyic's 正義部落
C範例 程式: 鍊結串列linked list. 使用結構(struct)實作節點(node). 串列建立在主程式中, 使用nodep * 型態傳進函式進行push 及pop.
#37. (原創) 簡單的Linked List實現(C/C++) (C) (Data Structure)
(原創) 簡單的Linked List實現(C/C++) (C) (Data Structure),使用C語言簡單的實現linkedlist,並用C++的std::vector實作出相同的功能作比較。
#38. Linked List Program in C - Tutorialspoint
A linked list is a sequence of data structures, which are connected together via links. Linked List is a sequence of links which contains items.
#39. 線性資料結構(Queue、Stack或Linked List) 與優先權佇列 ...
最後刪除最前面的元素,接著顯示Queue目前所有元素值到螢幕。 (b)預期程式執行結果. (c)範例程式如下. 1 2 3 ...
#40. LinkedList<T> 類別(System.Collections.Generic) - Microsoft ...
本文內容. 定義; 範例; 備註; 建構函式; 屬性; 方法; 明確介面實作; 擴充方法; 適用於; 執行緒 ...
#41. C-反轉鏈結串列(單鏈) - 睡在雲的彼端
listNode *nl; //nl:Next Link. } listNode * Inverse(listNode *str)//鏈結串列反轉範例 str 為鏈結串列的起始端 { listNode *ptr=str,*tmp=NULL; ...
#42. 【資料結構篇】連結串列(c語言)_其它 - 程式人生
After the insertion, the new node will be the first node of the linked list. */ void myLinkedListAddAtHead(MyLinkedList *obj, ...
#43. C/C++程式設計範例教本
「鏈結串列」(Linked Lists)是一種動態資料結構,如同火車掛車廂一般,將每一個車廂的節點連結起來,如下圖所示:. 11-3 基本鏈結串列-snode結構. C語言串列 ...
#44. Linked List的複習總結
Linked List 的複習總結,软件开发平台及语言笔记大全(超详细) ... 從以上可以看出在c++中Node一般是用struct來生成,並且可以使用constructor來初始化Node,因此 ...
#45. [問題] C語言Bubble Sort with linked-list - 看板C_and_CPP
各位大神好, 最近在學習C語言。 想要用linked-list寫bubble sort 這是我參考網路上的做法,最後有成功排序的程式碼#include.
#46. [問卦] C語言最難的部分是哪一個
真是磨人的妖孽。還有比Linked list更難的部分嗎?有沒有卦!--推frommr: hello world 01/04 14:52→ linceass: 摸到C罩杯01/04 14:52→ PONANZA: 罩杯01/04 14:52噓 c.
#47. 排序清單以Linked List 實做之參考程式
... 至大排序之單向鏈結串列的資料增刪與列印* //*【資料結構】: singly linked list ... 為一個node 指標,它指向下一個節點* //* class list : 定義list 為一個串列 ...
#48. 看似比較簡單的推坑教學C語言從崩潰到崩潰Ex(二) - SlideShare
這次總算把C語言EX下半部份的教學文完成了. ... 基本的資料結構介紹•陣列(array) •鍊結串列(Linked List) •堆疊(Stack) •佇列(Queue) •樹(Tree); 109.
#49. Data Structures Chapter 4 Linked Lists - AZSLIDE.COM
Representing Chains in C (用C 語言來表示鏈). ▻ Linked Stacks and Queues (鏈結堆疊與鏈結 ... A linked list is comprised of nodes; each node has zero or more.
#50. C語言雙向連結串列的實現(簡單實現) - IT閱讀
雙向使用的時候重要的是獲得連結串列頭和連結串列尾,下面有獲取的相關函式。 // copyright reserved by GongXu // doubly linked list for simple using ...
#51. Data - 演算法筆記
上面這些都是一筆資料的C++ 程式碼範例。可是如果有非常多筆資料怎麼辦呢 ... 雙向都串,稱作Doubly Linked List ,特色是雙向都能搜尋。 Doubly Linked List 若用XOR ...
#52. C++資料結構與演算法: 單向鏈結串列(下) | 自學程式誌
首先,我先宣告指標結構變數node,並且在資料成員的data要加入字串資料和指標變數next為NULL .然後,走訪鏈結串列找到資料尾端後,將此尾端的資料成員next指向新加入的 ...
#53. C語言鏈表詳解- 純淨天空
鏈表(Linked list)是一種常見的基礎數據結構,是一種線性表,但是並不會按線性的順序存儲數據,而是在每一個節點裏存到下一個節點的指針(Pointer)。 單 ...
#54. 純C 堆疊(先進後出) – 使用鏈結(Link)實作(C 語言動態記憶體 ...
純C 堆疊(先進後出) – 使用鏈結(Link)實作(C 語言動態記憶體 ... 刪除元素void list(Node*); // 顯示所有內容int main(void) { Node* sTop; ...
#55. 常見程式演算:: 阿姆斯壯數 - OpenHome.cc
C Java Python Scala Ruby JavaScript. Haskell. #include <stdio.h> #include <stdlib.h> int isNarcissistic(double); void narcissistic(double*, ...
#56. 結構(struct)
範例 : struct Student_PersonalData { char name[4]; int age; ... 這樣的(*(*listOne.next).next).data語法既難寫又難懂, 因此C語言定義了->運算符號。
#57. Linked lists - Learn C - Free Interactive C Tutorial
A linked list is a set of dynamically allocated nodes, arranged in such a way that each node contains one value and one pointer. The pointer always points to ...
#58. [C 常見考題] Linked List Allocation Quiz - 程式扎記
[C 常見考題] Linked List Allocation Quiz · PL createLL2() · { · PL head = NULL; · printf("\t[Info] Create LinkedList...\n"); · PPL lastref = &head; ...
#59. Leetcode#876 Middle of the Linked List @ 大家一起學AI - 痞客邦
該題Leetcode Middle of the Linked List為實現得到一半以後的鏈結串列,如以下所示,範例1共有5個鏈結串列節點(1、2、3、4、5),要取得中間以後的 ...
#60. LeetCode 19. Remove Nth Node From End of List ( C ) - Medium
Given the head of a linked list, remove the nth node from the end of the list and return its head. Example 1: Input: head = [1,2,3,4,5], ...
#61. 資料結構-鏈結串列(多項式相加) - 奇怪的(´・ω・`)增加了的部落格
資料結構-鏈結串列(多項式相加) ; int main() { POL *A,*B,*C; A = ; int main() { POL *A,*B,*C; A = ; void add_up_Node ...
#62. C++ list - 程式語言教學
按此前往C++完整教學目錄* 朋友們若是覺得本教學對您有幫助,請點個讚~ 串列(list): 為使用雙鍊結串列(double linked list)資料結構設計而成的容器。
#63. [資料結構]鏈結串列(Linked List)_基礎觀念_簡單易懂 - OOLIN
鏈結串列(Linked List):是由一個或一個以上動態記憶體分配的節點所組成,每一個節點至少會有兩個或兩個 ... 更多歐歐Lin 的資料結構(C語言) 推薦文章.
#64. 15 C語言的動態記憶體配置與鏈結串列 - 開放式課程
課程 · 電機資訊學院 · 電機工程學系 · 計算機程式(2020年版) · 課程內容 · 15 C語言的動態記憶體配置與鏈結串列. 15 C語言的動態記憶體配置與鏈結串列.
#65. 資料結構入門: 使用C語言(修訂版附範例光碟) | 誠品線上
資料結構入門: 使用C語言(修訂版附範例光碟):,以C語言的模組化程式設計實作各種 ... 雙佇列4-5 優先佇列第5章鏈結串列5-1 C語言的動態記憶體配置5-2 認識鏈結串列5-3 ...
#66. 【LeetCode】 206. Reverse Linked List C语言 - CSDN
Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* reverseList(struct ...
#67. 資料結構-使用C/C++語言(附範例光碟片)(第二版)
資料結構-使用C/C++語言(附範例光碟片)(第二版). □ 內容簡介 ... 3-13 環狀雙向鏈結串列結構(Circular Doubly Linked List) ... 5-6 多重佇列(Multi Linked List).
#68. 連結串列(Linked List) - 小殘的程式光廊
簡介連結串列(Linked List)是串列(List)的一種,是一種常見的資料結構, ... C++. 抽象類別 #ifndef LINKEDLIST_H #define LINKEDLIST_H #include ...
#69. c語言連結串列的排序,反序 - 程式前沿
void sort(LinkList *list){ LinkList *p, *q; list = list->next; for (p = list; p ->next != NULL; p = p->next){ int k = p->score; ...
#70. 鏈表實例程序(C語言) - 數據結構和算法教學 - 億聚網
下面是用C語言來實現鏈表的一個實例程序,具體細節如下: #include ... struct node *link = (struct node*) malloc(sizeof(struct node)); ... //is list empty
#71. C 語言學習筆記: 二元樹 - 小狐狸事務所
資料結構-使用C 語言(松崗, 陳會安); 圖說演算法-使用C 語言(博碩, ... 二元樹的資料結構可以使用鏈結串列(linked list) 或一維陣列表示, ...
#72. Linked List Data Structure - Programiz
In this tutorial, you will learn about linked list data structure and it's implementation in Python, Java, C, and C ...
#73. [C] XOR linked list - 邁向王者的旅途
[C] XOR linked list · 每一筆資料很小(< 16 bytes) · 有非常多筆資料(就算是比較小的測資也會有billion 筆以上的資料) · 程式效能跟我能cache 多少筆資料 ...
#74. 234. Palindrome Linked List,palindromelinked_關於C語言
... Linked List,palindromelinked. 日期:2017/1/21 10:09:38 編輯:關於C語言 ... Given a singly linked list, determine if it is a palindrome. Follow up:
#75. Linked List - 鏈表
反轉單向鏈表(singly linked list). 雙向鏈表 ... 鏈表是線性表(linear list)的一種。 ... C++. struct ListNode { int val; ListNode *next; ListNode(int val, ...
#76. C link list example | tool man xyz
此網站版面極為簡潔且不包含任何廣告,內容包含不好笑又尷尬的文章、覺得之後可能會看所以先保存但事後很少會看的新聞等。
#77. C語言基礎
C ++入門教學:輸入/輸出與運算 · C語言入門: 宣告,賦值,PRINTF · C 語言:結構(struct)自訂不同資料型態綁一起 · C語言 : 超好懂的指標,初學者請進~ · C 語言:鏈結串列( ...
#78. c語言教學篇[bohann's wiki]
在撰寫環狀佇列的程式,假如只使用front和rear註標,會有什麼缺點? 鏈結串列(linked list).
#79. [教學] Linked List / Linked List Sort - 一個小小工程師的心情 ...
昨天在處理資料,剛好用到,為防老人痴呆,還是記在自己的blog裡面比較保險,免得以後有用到還要想一下推一下這樣-_- || Linked List (鏈節串列)是 ...
#80. 用c語言寫linked list 長廊上的小偷
條件限制: 小偷背包最多能裝20kg的物品。 每樣物品以三個屬性表示之,分別為品名(char),價值(int),以及重量(float)。 長廊是一個queue(請以linked list ...
#81. C語言·鏈錶基礎必刷21題—— 三板斧(上) - 文章整合
C 語言·鏈錶基礎必刷21題—— 三板斧(上) ... 203. 移除鏈錶元素 https://leetcode-cn.com/problems/remove-linked-list-elements/description/ ...
#82. Linked List in C - Log2Base2
Sample Linked List Node ... struct node { int data; struct node *next; };. where,. data - used to store the integer information. struct node *next - It is used to ...
#83. C++ Tutorial - Linked List Examples - 2020 - BogoToBogo
Also, there is another set of linked list quiz. Example 1. #include <iostream> using namespace std; struct Node { int data; Node* next; }; // only ...
#84. C語言基於單鍊表得學生成績管理系統 - 每日頭條
首先給大家總結下為什麼你們學習C語言會覺得難,尤其是對於單鍊表這塊, ... void saveInfoToFile(struct Node* list, char *filePath, char *mode).
#85. linked list 鏈結串列(C language) - 漫遊於歷史與現代之間
在C語言中我們會這樣宣告: typedef struct dnode{ struct dnode *llink; int data; struct dnode *rlink; }dlist_node;
#86. [C 語言] 指標(pointer)
替函式提供傳入參數的方法(比方說陣列(Array)); 減少複製大塊記憶體,減少資源浪費; 支援某些資料結構(鏈結串列(Linked-List)).
#87. C 速查手冊- 6.3.1 自我參考的結構 - 程式語言教學誌
我們之前是將a 的nextPtr 設定成b 的位址,所以第二次進入迴圈時, startPtr 指向的是b ,之後的動作皆可類推。 這樣的資料結構稱之為鍵結串列(linked list) ,所有的資料 ...
#88. Linux 核心設計/實作(Linux Kernel Internals) - 成大資工Wiki
安排linked list 作為第一份作業及隨堂測驗的考量點: 檢驗學員對於C 語言指標操作的熟悉程度(附帶思考:對於Java 程式語言來說,該如何實作linked list 呢 ...
#89. 106 年公務人員普通考試試題 - 公職王
二、用C 語言撰寫一個函式,能反轉一單向鍊結串列(singly linked list): struct node* reverse(struct node *h)。 單向鍊結串列範圍如圖一。
#90. My data structure notes. C語言實作資料結構學習筆記 - GitHub
C 語言實作資料結構學習筆記. Contribute to liao2000/Data-Structure-in-C development by creating an account on GitHub. ... Linked-List · 01-基礎格式.c · 02-自 ...
#91. Re: [問卦] C語言最難的部分是哪一個- Gossiping板
這裡又用「豆」提醒大家,「葛」屬於豆科,用心良苦。 Linux 核心之父Linus Torvalds 在TED 2016 的訪談[1] 中,用linked list 程式碼. 作為解說「程式 ...
#92. Leetcode 程式解題基礎:linked list 和binary tree | Mr. Opengate
這篇主要是linked list 和binary tree 的程式解題小技巧彙整。 這些題目都很基礎不鑽牛角尖, ... 例如像下面的範例: Remove Linked List Elements
#93. Adjacency list representation of graph. Adjacency List ...
Corresponding to each vertex is a list (either an array or linked list) of its ... a list of adjacent nodes ; Example (undirected graph): A: B, C, D ; B: A, ...
#94. linked list c 排序 - Rantasa
因為在Linked List 中通常都需要考慮是不是head,那如果不想要那麼麻煩有一個小技巧就是 ... 主頁登錄/ 注冊社區C語言帖子詳情如何使用c語言對鏈表數據進行按姓名 ...
#95. C Linked List Data Structure Explained with an Example C ...
A Practical C Linked List Example · The first node is always made accessible through a global 'head' pointer. · Similarly there is a 'curr' ...
linked list c範例 在 [問題] C語言Bubble Sort with linked-list - 看板C_and_CPP 的推薦與評價
各位大神好,
最近在學習C語言。
想要用linked-list寫bubble sort
這是我參考網路上的做法,最後有成功排序的程式碼
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node *next;
};
void printLinkedList(struct node *start);
void swap(struct node *node1, struct node *node2);
void bubbleSort(struct node *start);
// ================================================
int main()
{
int arry[10];
struct node *prev, *first = NULL, *current;
printf("Please type in the 01st number:");
scanf("%d", &arry[0]);
printf("Please type in the 02nd number:");
scanf("%d", &arry[1]);
printf("Please type in the 03rd number:");
scanf("%d", &arry[2]);
printf("Please type in the 04th number:");
scanf("%d", &arry[3]);
printf("Please type in the 05th number:");
scanf("%d", &arry[4]);
printf("Please type in the 06th number:");
scanf("%d", &arry[5]);
printf("Please type in the 07th number:");
scanf("%d", &arry[6]);
printf("Please type in the 08th number:");
scanf("%d", &arry[7]);
printf("Please type in the 09th number:");
scanf("%d", &arry[8]);
printf("Please type in the 10th number:");
scanf("%d", &arry[9]);
int i;
for (i = 0; i < 10; i++)
{
current = (struct node*)malloc(sizeof(struct node));
current -> data = arry[i];
if (i == 0)
{
first = current;
}
else
{
prev -> next = current;
}
current -> next = NULL;
prev = current;
}
printf("\n");
printf("List before sorting:");
printLinkedList(first);
printf("\n");
bubbleSort(first);
printf("List after sorting:");
printLinkedList(first);
printf("\n\n");
return 0;
}
// ================================================
void printLinkedList(struct node *start)
{
struct node *tmp = start;
while(tmp != NULL)
{
printf("%d,", tmp -> data);
tmp = tmp -> next;
}
}
// ------------------------------------------------
void swap(struct node *node1, struct node *node2)
{
int tmp = node2 -> data;
node2 -> data = node1 -> data;
node1 -> data = tmp;
}
// ------------------------------------------------
void bubbleSort(struct node *start)
{
struct node *startSort;
struct node *endSort = NULL;
int swapped;
if (start == NULL)
{
return;
}
do
{
swapped = 0;
startSort = start;
while (startSort -> next != endSort)
{
if (startSort -> data >= startSort -> next -> data)
{
swap(startSort, startSort -> next);
swapped = 1;
}
startSort = startSort -> next;
}
endSort = startSort;
}
while (swapped);
}
以下是我的問題,
我原本的做法在bubbleSort子程式沒有加入swapped這個參數(如下),
但是網路上找到的做法都有這種旗標。
想請問兩種是否只差在我會多執行幾次多餘的while (startSort -> next != endSort)?
還是說我的做法會有什麼bug呢??
謝謝大家~
void bubbleSort(struct node *start)
{
struct node *startSort;
struct node *endSort = NULL;
int swapped;
if (start == NULL)
{
return;
}
while(1)
{
startSort = start;
while (startSort -> next != endSort)
{
if (startSort -> data >= startSort -> next -> data)
{
swap(startSort, startSort -> next);
}
startSort = startSort -> next;
}
endSort = startSort;
if (endSort == start -> next)
{
break;
}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.44.82.152 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1570504758.A.3A4.html
※ 編輯: airwaves (114.44.82.152 臺灣), 10/08/2019 11:22:21
※ 編輯: airwaves (114.44.82.152 臺灣), 10/08/2019 11:27:33
... <看更多>