69,373
社区成员
发帖
与我相关
我的任务
分享
taskList DeleteTask(taskList l, char* name){
if(l==NULL)
return NULL;
if(strcmp(l->name,name)==0){
if(l->prev==NULL&&l->next==NULL){
return NULL;
}
if(l->prev==NULL&&l->next!=NULL){
l=l->next;
l->prev=NULL;
l=DeleteTask(l,name);
return l;
}
else if(l->next==NULL &&l->prev!=NULL){
return NULL;
}else{
l=l->next;
l->prev=l->prev->prev;
l=DeleteTask(l,name);
return l;
}
}
l->next=DeleteTask(l->next,name);
return l;
}
typedef struct task{
struct task *prev;
struct task *next;
char *name;
unsigned int t;
int type;
int fre;
}taskNode, *taskList;
taskList CreateTask(unsigned int n_t, int n_fre,char *n_name, int n_type){
taskList l = (taskList)malloc(sizeof(taskNode));
l->t=n_t;
l->name= strdup(n_name);
l->type=n_type;
l->fre=n_fre;
l->prev=NULL;
l->next=NULL;
return l;
}
taskList InsertTask(taskList l, taskList n_l){
if(l==NULL)
return n_l;
if(n_l->t <= l->t){
if(l->prev==NULL){
n_l->next=l;
l->prev=n_l;
return n_l;
}
n_l->prev = l->prev;
n_l->next=l;
l->prev->next=n_l;
l->prev=n_l;
return n_l;
}
if(l->next==NULL){
l->next = n_l;
n_l->prev=l;
return l;
}
l->next = InsertTask(l->next, n_l);
return l;
}
int main(int argc, char **argv){
taskList t_list =NULL;
t_list = InsertTask(t_list,CreateTask(0,0,"a",0));
t_list = InsertTask(t_list,CreateTask(1,0,"b",0));
t_list = InsertTask(t_list,CreateTask(2,0,"c",0));
taskList temp =NULL;
temp= t_list;
t_list = InsertTask(t_list,CreateTask(3,0,"d",0));
t_list = InsertTask(t_list,CreateTask(4,0,"f",0));
if(temp->next==NULL)
printf("1s%d %s\n",temp->t,temp->name);
while(temp->next!=NULL){
printf("2s%d %s\n",temp->t,temp->name);
temp = temp->next;
}if(temp->next==NULL);
printf("3s%d %s\n",temp->t,temp->name);
return 0;
}
taskList temp=NULL;
temp=up;
if(FindSchedule(scheduler_list,current_time)==NULL){
scheduler_list=InsertSchedule(scheduler_list,CreateSchedule(current_time,NULL,temp));
}
else{
FindSchedule(scheduler_list,current_time)->upcomingTask = InsertTask(FindSchedule(scheduler_list,current_time)->upcomingTask,temp);
}