69,373
社区成员
发帖
与我相关
我的任务
分享
void
rearrange_FF()
{
struct free_block_type *pre1, *pre2, *count1, *count2, *tmp1, *tmp2;
pre1 = free_block_head;
for (count1 = free_block_head -> next; count1 != NULL; count1 = count1 -> next)
{
pre2 = count1;
for (count2 = count1 -> next; count2 != NULL; count2 = count2 -> next)
{
if (count1 -> start_addr > count2 -> start_addr)
{
tmp1 = count1 -> next;
tmp2 = count2 -> next;
pre1 -> next = count2;
pre2 -> next = count1;
count1 -> next = tmp2;
count2 -> next = tmp1;
}
pre2 = pre2 -> next;
}
pre1 = pre1 -> next;
}
}
110.Node *Sorted(Node *head)//简单的冒泡排序法
111.{
112. Node *p1,*p2;
113. p1=head;
114. p2=head;
115. int len=Length(head);
116. if (NULL==head||NULL==head->next)
117. return head;
118. for (int i=0; i<len; ++i)
119. {
120. p2=p1;
121. for (int j=i+1; j<len; ++j)
122. {
123. if(p1->data>p2->next->data)
124. {
125. p1->data^=p2->next->data;
126. p2->next->data^=p1->data;
127. p1->data^=p2->next->data;
128. }
129. p2=p2->next;
130. }
131. p1=p1->next;
132. }
133. return head;
134.}
void //怎么能事返回空????返回头指针 地址变了 应该引用
rearrange_FF()
{
struct free_block_type *pre1, *pre2, *count1, *count2, *tmp1, *tmp2;
pre1 = free_block_head;
for (count1 = free_block_head -> next; count1 != NULL; count1 = count1 -> next)
{
pre2 = count1;
for (count2 = count1 -> next; count2 != NULL; count2 = count2 -> next)
{
if (count1 -> start_addr > count2 -> start_addr)
{
tmp1 = count1 -> next;
tmp2 = count2 -> next;
pre1 -> next = count2;
pre2 -> next = count1;
count1 -> next = tmp2;
count2 -> next = tmp1;
}
pre2 = pre2 -> next;
}
pre1 = pre1 -> next;
}
}
http://blog.csdn.net/hondely/article/details/8115251
rearrange_FF()
{
struct free_block_type *pre1, *pre2, *count1, *count2, *tmp1, *tmp2;
int switched;
do
{
switched = 0;
pre1 = free_block_head;
for (count1 = free_block_head -> next; count1 != NULL && !switched; count1 = count1 -> next)
{
pre2 = count1;
for (count2 = count1 -> next; count2 != NULL; count2 = count2 -> next)
{
if (count1 -> start_addr > count2 -> start_addr)
{
tmp1 = count1 -> next;
tmp2 = count2 -> next;
pre1 -> next = count2;
if (tmp1 == count2) //交换2个相邻节点
{
count2 -> next = count1;
count1 -> next = tmp2;
count2 = count1;
}
else//交换2个不相邻节点
{
pre2 -> next = count1;
count1 -> next = tmp2;
count2 -> next = tmp1;
}
switched = 1;//交换后置标志switched为1,从而退出循环
break;
}
pre2 = pre2 -> next;
}
pre1 = pre1 -> next;
}
} while(switched);//交换过再重新开始循环
}
。