数据结构day3作业

1.顺序变按元素删除

void del_ele(sqlist *list,int key)
{
	if(list==NULL||empet_full(list))
		return;
	for(int i=0;ilen;i++){
		if(key==list->date[i])
			del_index(list,i);
	}
}
	int key;
	printf("please input key:");
	scanf("%d",&key);
	del_ele(list,key);
	output(list);

2.顺序表按元素修改

void find_ele(sqlist* list,int key,int element)
{
	if(NULL==list||empet_full(list))	
		return;
	int index=search_date(list,key);
	list->date[index]=element;
}
	int key;
	int element1;
	printf("please input key:");
	scanf("%d",&key);
	printf("please input element:");
	scanf("%d",&element1);
	find_ele(list,key,element1);
	output(list);

3.顺序表排序

void sort(sqlist *list,int flag)
{
	if(flag==1){
		for(int i=0;ilen-1;i++){
			for(int j=0;jlen-i-1;j++){
				if(list->date[j] > list->date[j+1]){
					list->date[j] ^= list->date[j+1];
					list->date[j+1] ^= list->date[j];
					list->date[j] ^= list->date[j+1];
				}
			}
		}
	}
	if(flag==0){
		for(int i=0;ilen-1;i++){
			for(int j=0;jlen-i-1;j++){
				if(list->date[j] < list->date[j+1]){
					list->date[j] ^= list->date[j+1];
					list->date[j+1] ^= list->date[j];
					list->date[j] ^= list->date[j+1];
				}
			}
		}
	}
}
	int flag;
	printf("please input flag 1/0");
	scanf("%d",&flag);
	sort(list,flag);
	output(list);

4.顺序表释放空间

sqlist* free_space(sqlist *list)
{
	if(NULL==list)
		return list;
	free(list);
	list=NULL;
	return list;
}

5.顺序表有序合并

void combine_date(sqlist* la,sqlist* lb,sqlist* lc)
{
	int p=0;
	int q=0;
	int r=0;
	//la和lb都有元素
	while(plen&&qlen)
	{
		if(la->date[p]<=lb->date[q])
		{
			lc->date[r]=la->date[p];
			p++;
			r++;
			lc->len++;
		}
		else
		{
			lc->date[r]=lb->date[q];
			q++;
			r++;
			lc->len++;
		}

	}
	//la没有元素,lb有元素
	while(qlen)
	{
		lc->date[r]=lb->date[q];
		r++;
		q++;
		lc->len++;
	}
	//ba没有元素,la有元素
	while(plen)
	{
		lc->date[r]=la->date[p];
		r++;
		p++;
		lc->len++;
	}
}
	sqlist *la=creat_space();
	sqlist *lb=creat_space();
	sqlist *lc=creat_space();
	int n;
	printf("please inout num");
	scanf("%d",&n);
	date_type element;
	//输入
	for(int i=0;i

你可能感兴趣的:(数据结构)