2.22作业

test.c

cpp 复制代码
#include "test.h"
seq_p creat_list(){
	seq_p L=(seq_p)malloc(sizeof(seq_list));
	if(L==NULL){
		printf("申请空间失败\n");
		return 0;
	}
	L->len=0;
	return L;
}
int seq_p_empt(seq_p L){
	if(L=NULL){
		return -12;
	}
	return L->len==0?1:0;
}
int seq_p_full(seq_p L){
	if(L=NULL){
		return -23;
	}
	return L->len==MAX?1:0;
}
void insert_pos(seq_p L,datatpye num,int point){
	if(L=NULL){
		return;
	}
	if(seq_p_full(L)){
		printf("顺序表已满\n");
		return;
	}
	for(int i=L->len-1;i>=point;i--){
		L->data[i+1]=L->data[i];
	}
	L->data[point]=num;
	L->len++;
}
void del_pos(seq_p L,int point){
	if(L==NULL){
		return;
	}
	if(seq_p_empt(L)){
		printf("该线性表是空表\n");
	}
	for(int i=point;i<L->len-1;i++){
		L->data[i]=L->data[i+1];
	}
	L->len--;
}
void del(seq_p L){
	if(L==NULL){
		return;
	}
	if(seq_p_empt(L)){
		printf("线性表为空\n");
	}
	if(L->len==1){
		printf("线性表的长度为一\n");
	}
	for(int i=0;i<L->len;i++){
		for(int j=i+1;j<L->len;j++){
			if(L->data[i]==L->data[j]){
				L->data[j]=L->data[j+1];
				j--;
				L->len--;
			}
		}
	}
}
void s1(seq_p L){
	for(int i=0;i<L->len;i++){
		printf("%d ",L->data[i]);
	}
}

main.c

cpp 复制代码
#include "test.h"
int main(){
	seq_p L= creat_list();
	insert_pos(L,1,0);
	insert_pos(L,2,1);
	insert_pos(L,3,2);
	insert_pos(L,4,3);
	insert_pos(L,5,4);
	insert_pos(L,4,5);
	insert_pos(L,3,6);
	insert_pos(L,6,7);
	s1(L);
	del_pos(L,2);
	s1(L);
	del(L);
	s1(L);
}

test,h

cpp 复制代码
#ifndef __TEST_H__
#define __TEST_H__
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
typedef int datatpye;
typedef struct seq_list{
	datatpye data[MAX];
	int len;
}seq_list,*seq_p;

seq_p creat_list();
int seq_p_empt(seq_p L);
int seq_p_full(seq_p L);
void insert_pos(seq_p L,datatpye num,int point);
void del_pos(seq_p L,int point);
void del(seq_p L);

void s1(seq_p L);
#endif
相关推荐
uppp»38 分钟前
深入理解 Java 反射机制:获取类信息与动态操作
java·开发语言
程序员yt40 分钟前
双非一本电子信息专业自学嵌入式,学完 Linux 后咋走?单片机 & FreeRTOS 要补吗?
linux·运维·单片机
m0_748256144 小时前
SpringBoot
java·spring boot·后端
阿华的代码王国5 小时前
【从0做项目】Java搜索引擎(3)
java·搜索引擎·项目
Mr.朱鹏5 小时前
针对Feign客户端请求体参数处理问题
java·jvm·spring boot·spring·spring cloud·maven·intellij-idea
安於宿命5 小时前
【Linux】进程间通信——进程池
linux·c++
新兴ICT项目支撑6 小时前
天翼云910B部署DeepSeek蒸馏70B LLaMA模型实践总结
linux·运维·服务器·910b·天翼云·deepseek r1
涛粒子7 小时前
Spring Bean 生命周期的执行流程
java·后端·spring
刘_sy7 小时前
使用EasyExcel和多线程实现高效数据导出
java·excel·easyexcel·批量导出excel
梦幻通灵7 小时前
IDEA通过Contince接入Deepseek
java·ide·intellij-idea