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
相关推荐
自由鬼17 分钟前
正向代理服务器Squid:功能、架构、部署与应用深度解析
java·运维·服务器·程序人生·安全·架构·代理
许白掰23 分钟前
Linux入门篇学习——Linux 编写第一个自己的命令
linux·运维·数据库·嵌入式硬件·学习
打不了嗝 ᥬ᭄29 分钟前
文件系统----底层架构
linux·运维·数据库
cui_win43 分钟前
【网络】Linux 内核优化实战 - net.ipv4.tcp_keepalive_time
linux·网络·tcp/ip
fouryears_234171 小时前
深入拆解Spring核心思想之一:IoC
java·后端·spring
codervibe1 小时前
使用 Spring Boot + JWT 实现多角色登录认证(附完整流程图)
java·后端
kfepiza1 小时前
Linux创建网桥Bridge的方法有哪些? 笔记250710
linux·tcp/ip
坚持学习永不言弃1 小时前
Ehcache、Caffeine、Memcached和Redis缓存
java
阿劲1 小时前
从业务卡顿到数据库连接池耗尽:Spring Boot项目HikariCP超时问题实战排查
java·后端·面试
亮1112 小时前
Maven 编译过程中发生了 Java Heap Space 内存溢出(OutOfMemoryError)
java·开发语言·maven