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
相关推荐
YXXY3136 小时前
线程的介绍(四)
linux
许彰午6 小时前
14_Java泛型完全指南
java·windows·python
智慧物业老杨7 小时前
司法绿色通道下的物业纠纷数智化解决方案——基于“三优先“机制的全流程技术落地实践
java·django
2601_961194027 小时前
2026初级会计实务公式总结大全|计算题公式手册PDF
java·spring·eclipse·pdf·tomcat·hibernate
做个文艺程序员7 小时前
第1篇:K8s 核心概念精讲:Pod、Deployment、Service 与 Namespace——Java 开发者快速上手指南
java·云原生·容器·kubernetes·容器编排
流星白龙7 小时前
【MySQL高阶】19.变更缓冲区,自适应哈希索引,日志缓冲区
数据库·windows·mysql
ylscode8 小时前
Comodo防火墙曝致命零日漏洞:单个IPv6数据包即可触发Windows蓝屏死机
运维·网络·windows·安全·安全威胁分析
kTR2hD1qb8 小时前
从 Responses API 到 Chat Completions:一个模型网关的设计复盘
linux·前端
姓刘的哦9 小时前
大模型祛魅
linux
x***r1519 小时前
nvm-windows 安装教程:Node.js 多版本管理(避坑版)
windows·node.js