Single LinkList 单向串行链结
洛爾大嬸 2019-03-23 11:48:04 各位高手们好,小妹正在自修串炼连结,遇到以下问题
以下是程序代码:
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 之后的部分看不懂,想求大神解释。