[問題] 串鍊鏈結,新增節點函數問題
各位高手們好,小的在自修串鍊連結遇到以下問題
在想如何寫一個"單向鏈結串列"的新增函數
以下是我參考的書籍所寫的程式碼
-----------------我是分隔線-----------------------------------
struct student {
char name[20];
int score;
struct student *next;
}
struct student *ptr,*head,*current,*prev;
void insert_func(void){
ptr = (struct student *)malloc(sizeof(struct student));
ptr->name =(char *)”John”;
ptr->score = (int *) 85;
prev = head;
current = head->next;
while((current != NULL) && (current->score > ptr->score) ){
prev = currect;
current = current->next;
}
ptr->next = current;
prev->next = ptr;
}
---------------------我是分隔線-----------------------------------------
以上是串鍊連結的程式碼,目的是"新增node並排序"。
我想請教 insert_func()中的程式碼,指標 prev = head 之後的部分看不懂,想求大神
解釋。
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.129.55.180
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1553312592.A.D6A.html
→
03/23 13:45,
6年前
, 1F
03/23 13:45, 1F
推
03/23 23:08,
6年前
, 2F
03/23 23:08, 2F
→
03/24 03:38,
6年前
, 3F
03/24 03:38, 3F
→
03/24 03:39,
6年前
, 4F
03/24 03:39, 4F
推
03/24 04:25,
6年前
, 5F
03/24 04:25, 5F
→
03/24 04:25,
6年前
, 6F
03/24 04:25, 6F
→
03/24 04:25,
6年前
, 7F
03/24 04:25, 7F
→
03/24 04:25,
6年前
, 8F
03/24 04:25, 8F
→
03/24 04:25,
6年前
, 9F
03/24 04:25, 9F
→
03/24 04:57,
6年前
, 10F
03/24 04:57, 10F
→
03/24 09:09,
6年前
, 11F
03/24 09:09, 11F
推
03/24 11:49,
6年前
, 12F
03/24 11:49, 12F
→
03/24 13:03,
6年前
, 13F
03/24 13:03, 13F
推
03/24 13:06,
6年前
, 14F
03/24 13:06, 14F
→
03/24 13:06,
6年前
, 15F
03/24 13:06, 15F
→
03/24 13:13,
6年前
, 16F
03/24 13:13, 16F
→
03/24 13:13,
6年前
, 17F
03/24 13:13, 17F