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
相关推荐
遥远_3 分钟前
电商履约大促峰值应对:核心业务数据预热方案详解
java·spring·1024程序员节·电商大促·数据预热
FJW02081411 分钟前
【Linux】用户管理及优化
linux·运维·服务器
---学无止境---16 分钟前
Linux中内核和用户空间通信send_uevent函数的实现
linux·网络
lemon_sjdk17 分钟前
每天学习一个新注解——@SafeVarargs
java
RoboWizard19 分钟前
电脑效能跃升利器 金士顿KVR内存焕新机
java·spring·智能手机·电脑·金士顿
读书读傻了哟33 分钟前
Windows 10 下 VS Code 配置 C++ 开发环境(MinGW)
c++·windows·mingw
微露清风42 分钟前
系统性学习C++-第七讲-string类
java·c++·学习
艾莉丝努力练剑42 分钟前
【C++:继承】C++面向对象继承全面解析:派生类构造、多继承、菱形虚拟继承与设计模式实践
linux·开发语言·c++·人工智能·stl·1024程序员节
报错小能手1 小时前
项目——基于C/S架构的预约系统平台(3)
linux·开发语言·笔记·学习·架构·1024程序员节
心寒丶1 小时前
Linux基础知识(三、Linux常见操作目录命令)
linux·运维·服务器·1024程序员节