没写完的代码先搁着

阅读: 评论:0

没写完的代码先搁着

没写完的代码先搁着

#include <iostream>
using namespace std;
struct Task{int ID;//任务编号int key;//任务优先级int load;//任务持续时间Task *next;
};
Task* getBatch(int count)
{int i,key1;Task *head,*p,*q;cin>>key1;head=new Task;cin>>head->ID>>head->load;head->key=key1;head->next=NULL;q=head;for(i=0;i<count-1;i++){p=new Task;cin>>p->ID>>p->load;p->key=key1;q->next=p;q=p;}return head;
}
Task* addBatch(Task *head, Task *h)
{Task *p,*q1,*q;p=head;q=h;q1=head;for(;q->next!=NULL;q=q->next);for(;p->next!=NULL;p=p->next){if(h->key<head->key)//插入在头部 {q->next=head;return q1;} if(p->key<=h->key&&p->next->key>=h->key)//插入在中间 {q->next=p->next;p->next=q1;return head;}}if(p->key<=h->key){p->next=q1;return head;}
}
void display(Task *head, int m)
{Task *p,*p1;int i=0,j;for(p=head;p->next!=NULL;p=p->next){i++;}if(i<m){cout<<"OK"<<endl;}else if(i>=m){for(j=0,p=head;j<m;p=p->next);cout<<p->ID<<" "<<p->key<<" "<<p->load<<endl; }
}
Task* study(Task*head, int mi, int ma, int load)
{Task *p,*p1,*p2;p=p1=p2=head;for(;p->next!=NULL;p=p->next);while(p2->next!=NULL&&load>0)//结点的删除 全部一起考虑 {if(p2==head){if(p2->load<=ma&&p2->load>=mi){if(load-p2->load>=0) load-=p2->load;p1=p1->next;delete head;}}else{if(p2->next->load<=ma&&p2->next->load>=mi){if(load-p2->next->load>=0){ load-=p2->next->load;Task *q;q=p2->next;p2->next=p2->next->next; delete q;}}}p2=p2->next;}return p1;
}
void del(Task* head){//删除链表if(head==NULL) return;del(head->next);delete head;
}
const int K=3;//幸运数字
int main(){int count, mi, ma, load;Task *head=NULL, *h;cin>>count;//输入行的第一个数字while(count!=0){if(count>0){   //新添加count个任务h=getBatch(count);//构建链表,并将首指针返回给hdisplay(h, K);//显示小链表的第K个任务或输出OKhead=addBatch(head, h);//将小链表加入大链表,并将首指针返回}else{cin>>mi>>ma>>load;head=study(head, mi, ma, load);display(head,K);//显示大链表的第K个任务或输出OK}cin>>count;		}del(head);return 0;
}

本文发布于:2024-02-01 01:16:04,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170672136432781.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:写完   代码   先搁着
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23