在华清远见培训日记#day21

思维导图

作业:完成双向链表的剩余功能

#include "head.h"

Double_List_Ptr Headnode_Create()
{
	Double_List_Ptr H=(Double_List_Ptr)malloc(sizeof(Double_List));
	if(H==NULL)
	{
		printf("head node create failed!\n");
		return NULL;
	}
	printf("head node create successfully!\n");
	H->prev=NULL;
	H->len=0;
	H->next=0;
	return H;
}

Double_List_Ptr Regularnode_Create(Datatype node_data)
{
	Double_List_Ptr P=(Double_List_Ptr)malloc(sizeof(Double_List));
	if(P==NULL)
	return NULL;
	P->prev=NULL;
	P->data=node_data;
	P->next=NULL;
	return P;
}

int Double_List_Empty(Double_List_Ptr H)
{
	if(H==NULL)
	return -1;
	return H->len==0;
	
}

void Head_add(Double_List_Ptr H,Datatype Add_data)
{
	Double_List_Ptr P=Regularnode_Create(Add_data);
	if(H==NULL)
	{
		printf("head add failed!\n");
		return;
	}
	printf("head add successfully!\n");
	if(Double_List_Empty(H))
	{
		H->next=P;
		P->prev=H;
	}
	else
	{
		P->next=H->next;
		H->next->prev=P;
		H->next=P;
		P->prev=H;
	}
	H->len++;
}


void Last_add(Double_List_Ptr H,Datatype Add_data)
{
	Double_List_Ptr P=Regularnode_Create(Add_data);
	if(H==NULL)
	{
		printf("last add failed!\n");
		return;
	}
	Double_List_Ptr S=H;
	printf("last add successfully!\n");
	if(Double_List_Empty(H))
	{
		H->next=P;
		P->prev=H;
	}
	else
	{
		for(int i=0;i<H->len;i++)
		{
			S=S->next;
		}
		S->next=P;
		P->prev=S;
	}
	H->len++;
}

void Show_Double_List(Double_List_Ptr H)
{
	if(H==NULL || Double_List_Empty(H))
	{
		printf("show double list failed!\n");
		return;
	}
	printf("show double list successfully!\n");
	Double_List_Ptr P=H;
	for(int i=0;i<H->len;i++)
	{
		P=P->next;
		printf("%d\n",P->data);
	}
}

void Insert(Double_List_Ptr H,int location,Datatype Insert_data)
{
	Double_List_Ptr P=Regularnode_Create(Insert_data);
	if(H==NULL || location<1)
	{
		printf("insert failed!\n");
		return;
	}
	printf("insert successfully!\n");
	Double_List_Ptr S=H;
	if(Double_List_Empty(H))
	{
		P->next=NULL;
		P->prev=H;
		H->next=P;
		H->len++;
	}
	else if(location>H->len)
	{
	for(int i=0;i<location-1;i++)
	{
		S=S->next;
	}
	P->next=S->next;
	S->next->prev=P;
	P->prev=S;
	S->next=P;
	H->len++;
	}
	else
	{
		P->next=H->next;
		H->next->prev=P;
		H->next=P;
		P->prev=H;
		H->len++;
	}
}

void Head_delete(Double_List_Ptr H)
{
	if(H==NULL || Double_List_Empty(H))
	{
		printf("head delete failed!\n");
		return;
	}
	printf("head delete successfully!\n");
	Double_List_Ptr P=H->next;
	if(H->len!=1)
	{
		H->next=P->next;
		P->next->prev=H;
		H->len--;
		free(P);
		P=NULL;
	}
	else
	{
		H->next=NULL;
		H->len--;
		free(P);
		P=NULL;
	}
}

void Last_delete(Double_List_Ptr H)
{
	if(H==NULL || Double_List_Empty(H))
	{
		printf("last delete failed!\n");
		return;
	}
	printf("last delete successfully!\n");
	Double_List_Ptr P=H;
	if(H->len!=1)
	{
		for(int i=0;i<H->len-1;i++)
		{
			P=P->next;
		}
		P->next->prev=NULL;
		Double_List_Ptr S=P->next;
		free(S);
		S=NULL;
		P->next=NULL;
		H->len--;
	}
	else
	{
		P=H->next;
		P->prev=NULL;
		H->next=NULL;
		free(P);
		P=NULL;
		H->len--;
	}
}

void Any_delete(Double_List_Ptr H,int location)
{
	if(H==NULL || Double_List_Empty(H) || location<1 || location>H->len)
	{
		printf("anywhere delete failed!\n");
		return;
	}
	printf("anywhere delete successfully!\n");
	Double_List_Ptr P=H;
	Double_List_Ptr S=H;
	for(int i=0;i<location;i++)
	{
		P=P->next;
	}
	if(H->len!=1)
	{
		for(int j=0;j<location-1;j++)
		{
			S=S->next;
		}
		S->next=P->next;
		P->next->prev=S;
		free(P);
		P=NULL;
		H->len--;
	}
	else
	{
		P->prev=NULL;
		S->next=NULL;
		free(P);
		P=NULL;
		H->len--;
	}
}

void Modify_bylocation(Double_List_Ptr H,int location,Datatype mod_data)
{
	if(H==NULL || Double_List_Empty(H) || location<1 || location>H->len)
	{
		printf("modify by location failed!\n");
		return;
	}
	printf("modify by location successfully!\n");
	Double_List_Ptr P=H;
	for(int i=0;i<location;i++)
	{
		P=P->next;
	}
	P->data=mod_data;
}

void Modify_byvalue(Double_List_Ptr H,Datatype value,Datatype mod_data)
{
	if(H==NULL || Double_List_Empty(H))
	{
		printf("modify by value failed!\n");
		return;
	}
	printf("modify by value successfully!\n");
	Double_List_Ptr P=H->next;
	while(P->data!=value && P->next!=NULL)
	{
		P=P->next;
	}
	P->data=mod_data;
	if(P->next==NULL)
	{
		printf("we cannot find the value,cannot modify!\n");
	}
}

void Find_bylocation(Double_List_Ptr H,int location)
{
	if(H==NULL || Double_List_Empty(H) || location<1 || location>H->len)
	{
		printf("find by location failed!\n");
		return;
	}
	printf("find by location successfully!\n");
	Double_List_Ptr P=H;
	for(int i=0;i<location;i++)
	{
		P=P->next;
	}
	printf("Value of the location is:%d\n",P->data);
}

void Find_byvalue(Double_List_Ptr H,Datatype find_data)
{
	if(H==NULL || Double_List_Empty(H))
	{
		printf("find by value failed!\n");
		return;
	}
	printf("find by value successfully!\n");
	Double_List_Ptr P=H->next;
	while(P->data!=find_data && P->next!=NULL)
	{
		P=P->next;
	}
	printf("Location of the value is:%p\n",P);
	if(P->next==NULL && P->data!=find_data)
	{
		printf("we cannot find the value,cannot find!\n");
	}

}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在Android开发中,`TIMELINE.DiffTimeReloadTask`通常用于异步加载和更新Timeline的数据。`onReloading(Day day)`方法可能是一个回调,当特定日期(Day)的数据需要重新加载时会被调用。`Day`可能是自定义的时间线条目,代表一天内的事件。 关于`DiffTimeReloadTask.DAY.onReloading`的具体实现,由于没有直接的代码片段可用,我们可以推测它的大概结构。这个方法可能会执行以下操作: 1. **检查缓存**[^1]: ```java List<TimelineItem> itemsFromCache = cache.get(day); ``` 2. **如果缓存中有数据,直接返回**: ```java if (itemsFromCache != null) { return itemsFromCache; } ``` 3. **开始网络请求或数据库查询**: ```java timelineService.getDataForDay(day, new Callback<List<TimelineItem>>() { @Override public void onResponse(List<TimelineItem> items) { // 更新缓存并同步到视图 updateCache(day, items); onItemsLoaded(items); } @Override public void onFailure(Exception e) { // 处理加载失败 handleLoadFailure(e); } }); ``` `getItems()`方法可能会在`onResponse`里被用来获取实际的事件项列表: ```java private void onItemsLoaded(List<TimelineItem> items) { DiffResult<TimelineItem> result = DiffUtil.calculateDiff(new TimelineItemComparator(), items, oldItems); DAY.setItems(result.newItems, result.changedItems, result.deletedItems); DAY.notifyDataSetChanged(); } ``` 这里的`TimelineItemComparator`用于比较新旧数据以决定哪些项目需要添加、更改或删除。` DiffResult`包含了这些信息,`setItems`方法则负责更新UI。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值