线性表总结
#1.代码段1:冒泡排序
##1.1.
void BubbleSort(struct Node * head) //1
{ //2
struct Node * p, * q, * tail; //3
while((head->next->next) != tail) //5
{ //6
p = head; //7
q = head->next; //8
while(q->next != tail) //9
{ //10
if((q->data) > (q->next->data)) //11
{ //12
p->next = q->next; //13
q->next = q->next->next; //14
p->next->next = q; //15
q = p->next; //16
} //17
q = q->next; //18
p = p->next; //19
} //20
tail = q; //21
} //22
} //23
##2.1.
int Find(LinkList L, int m ) //1
{ //2
LinkList p=L,q=L; //3
if (m<=0) //4
return -1; //5
while(m){ //6
if (!q->next) //7
return -1; //8
q=q->next; //9
m--; //10
} //11
p=p->next; //12
while(q->next){ //13
p=p->next; //14
q=q->next; //15
} //16
return p->data; //17
} //18
##2.2.
不懂的地方:
第12行到第17行,功能不懂,该代码段先检查输入的倒数第m个位置是否有效,在找出倒数第m个数据,第12好行到第17行的操作不太懂。