请教大佬,求解

小白爱编程 2019-04-06 09:06:43
#include <stdio.h> #include <stdlib.h> typedef struct node{ int data; struct node *prior; struct node *next; }T; T *creat1(int n){ T *head,*p,*L; int i; head=(T *)malloc(sizeof(T)); head->prior=NULL; head->next=NULL; L=head; for(i=0;i<n;i++) { p=(T *)malloc(sizeof(T)); p->data=rand()%11; p->next=L->next; if(L->next!=NULL){ L->next->prior=p; } L->next=p; p->prior=L; } return head; } T *creat2(){ T *head; head=(T *)malloc(sizeof(T)); head->prior=NULL; head->next=NULL; return head; } void print(T *head){ T *h=head; while(h->next!=NULL){ h=h->next; printf("%d\n",h->data); } } void LRU_List(T *head1,T *head2,int j,int n){ int i,b=0,k=0,flag=0; T *e,*L,*h; for(i=1;i<=n;i++){ e=head1->next; b=0; printf("第%d次\n",i); if(head2->next==NULL){ head1->next=e->next; e->next->prior=head1; e->next=head2->next; if(head2->next!=NULL){ head2->next->prior=e; } head2->next=e; e->prior=head2; k=k+1; } else{ L=head2; while(L->next!=NULL){ L=L->next; b=b+1; if(e->data==L->data){ flag=1; break; } else{ flag=0; } } if(flag!=1){ head1->next=e->next; e->next->prior=head1; e->next=head2->next; head2->next->prior=e; head2->next=e; e->prior=head2; k=k+1; } else{ head1->next=e->next; e->next->prior=head1; if(b!=1){ L->next->prior=L->prior; L->prior->next=L->next; L->next=head2->next; head2->next->prior=L; L->prior=head2; head2->next=L; } } } if(k==j+1){ h=head2; while(h->next!=NULL){ h=h->next; } h->prior->next=NULL; k=j; } printf("K=%d\n",k); print(head2); } printf("最终结果:"); print(head2); } void main(){ T *head1,*head2; int n,j; printf("请输入有多少个节点:"); scanf("%d",&n); head1=creat1(n); print(head1); printf("\n物理块数量:"); scanf("%d",&j); head2=creat2(); LRU_List(head1,head2,j,n); }
...全文
35 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
吉普赛的歌 2019-04-06
  • 打赏
  • 举报
回复
建议发到c++相关版块
小白爱编程 2019-04-06
  • 打赏
  • 举报
回复
图片糊掉了

11,849

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 非技术版
社区管理员
  • 非技术版社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧