//定义一个排序函数,参数为一个链表头结点指针phead void Sort(pnode phead) { pnode p, q;//定义两个指针 node temp;//定义一个临时变量 //循环遍历链表,从头结点的下一个节点开始 for(p=phead->pnext;NULL!=p;p=p->pnext) { //再次循环遍历链表,从当前节点的下一个节点开始 for(q=p->pnext;NULL!=q;q=q->pnext) { //如果当前一个学生的总分小于后一个学生的总分时 if(p->st.Totalst.Total) { //交换学生的位置 temp.st=p->st; p->st=q->st; q->st=temp.st; } } } }

为下列代码添加注释void Sortpnode phead	pnode p q;定义两个指针	node temp;	forp=phead-pnext;NULL!=p;p=p-pnext			forq=p-pnext;NULL!=q;q=q-pnext 					ifp-stTotalq-stTotal当前一个学生的总分小于后一个学生的总分时 							tempst=p-st; 交换

原文地址: http://www.cveoy.top/t/topic/fYg8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录