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
相关推荐
何双新34 分钟前
第21讲、Odoo 18 配置机制详解
linux·python·开源
21号 135 分钟前
9.进程间通信
linux·运维·服务器
朝新_4 小时前
【多线程初阶】阻塞队列 & 生产者消费者模型
java·开发语言·javaee
立莹Sir4 小时前
Calendar类日期设置进位问题
java·开发语言
季鸢5 小时前
Java设计模式之状态模式详解
java·设计模式·状态模式
@yanyu6666 小时前
springboot实现查询学生
java·spring boot·后端
ascarl20106 小时前
准确--k8s cgroup问题排查
java·开发语言
magic 2456 小时前
Lombok 的 @Data 注解失效,未生成 getter/setter 方法引发的HTTP 406 错误
java
Gaoithe6 小时前
ubuntu 端口复用
linux·运维·ubuntu
爱敲代码的憨仔6 小时前
分布式协同自动化办公系统-工作流引擎-流程设计
java·flowable·oa