循环首次适应算法首次适应算法最佳适应算法C语言版.docVIP

  • 640
  • 0
  • 约4.67千字
  • 约 9页
  • 2017-03-08 发布于重庆
  • 举报

循环首次适应算法首次适应算法最佳适应算法C语言版.doc

循环首次适应算法首次适应算法最佳适应算法C语言版

#include #define getpch type type* malloc sizeof type struct LNode int size; int start; int end; struct LNode *next; struct LNode *front; *L; /*L为头指针*/ typedef struct LNode LN; LN *find; int n; void InsertList int size,int start // 在带头结点的单链线形表头结点后插入 LN *p,*s,*t; p L; t p- next; s getpch LN ; //生成新结点 s- size size; s- start start; s- end start + size ; s- next t; //插入L中 p- next s; if t t- front s; s- front p; //end of InsertList void PrintList /*打印*/ LN *p; int i; p L- next; printf \n空闲区号 长度 起始位置 终止位置\n ; for i 1;i n;i++ printf %3d\t %3d\t%3d\t %4d\n,i,p- size, p- start,p- end ; p p- next; void BFSortList /*最佳适应算法的排序*/ LN *p,*s,*t; int min_size,i; int size,start,end; t L- next; p L- next; for i 0;i n;i++ s p- next; min_size p- size; while s if min_size s- size min_size s- size; t s; s s- next; size t- size; start t- start; end t- end; t- size p- size; t- start p- start; t- end p- end; p- size size; p- start start; p- end end; t p- next; p p- next; // end of BF_SortList void SortList /*首次和循环首次适应算法的排序*/ LN *p,*s,*t; int min_start,i; int size,start,end; t L- next; p L- next; for i 0;i n;i++ s p- next; min_start p- start; while s if min_start s- start min_start s- start; t s; s s- next; size t- size; start t- start; end t- end; t- size p- size; t- start p- start; t- end p- end; p- size size; p- start start; p- end end; t p- next; p p- next; // end of BF_SortList void GetFree /*生成空闲分区链*/ int size,start,i; L getpch LN ; /*生成一个表头结点*/ L- next NULL; L- front NULL; printf 请输入空闲区数: ; scanf %d,n ; for i 1;i n;i++ printf 请输入第%2d空闲区的大小和始址:,i ; scanf %3d,%3d,size,start ; InsertList size,start ; printf \n按任意键继续 ; //printf \n空闲链表情况:\n ; //PrintList ; // end of GetFree void Assign int size /*最佳适应算法和首次适应算法空闲分区的分配*/ LN *p,*t; p L- next; t L; while p if size p- size p p- next; t t- next; if !p printf 没有足够大的空闲区分配!分配不成功 ; else p- size p- size - size; p- start

文档评论(0)

1亿VIP精品文档

相关文档