#include<stdio.h> /* 01 构建链表 02 初始化链表 ?注意头节点 直接赋值 03 输出链表? */ ? struct stu{ ? ? ? ? int num; ? ? ? ? float score; ? ? ? ? struct stu *next; }; //前插 void Sort(struct stu a,struct stu b,struct stu c,struct stu *head) { ?? ?head = &a; ? ? a.next = &b; ? ? c.next = &b; ? ? a.next=&c; ? ? b.next=NULL;
? ? do{ ? ? ? ? printf("student number: %d score:%f\n",head->num, head->score); ? ? ? ? ? ?head = head->next; //head->next = head ? }while(head); ? }? ?// 后插 ?void Sort1(struct stu a,struct stu b,struct stu c,struct stu *head) { ?? ?head = &a; ? ? a.next = &b; ? ? b.next = &c; ? ? c.next = NULL; ? ? do{ ? ? ? ? printf("student number: %d score:%f\n",head->num, head->score); ? ? ? ? head = head->next; //head->next = head ? }while(head); ? } int main(){ ? ? struct stu a, b, c, *head; a.num =1; a.score = 89; ? b.num = 2 ; b.score = 98; ? c.num = 3; c.score = 99; ? head = &a; a.next = &b; b.next = &c; c.next = NULL; ?? do{ ? ? ? ? printf("student number: %d score:%f\n",head->num, head->score); ? ? ? ? ? ?head = ? ? ? ?head->next; //head->next = head }while(head); ? return 0; }?
|