一个增删改查插的线性表(一)

    又是美好的一天结束了,为了让被催作业的每一天过得不是那么痛苦,睡觉之前上传一下最近写的一个拥有初始化、增删改查、指定位置读取、修改,插入元素,读取指定位置下标的一个链表代码

seqlist.h

#pragma once

#include

#define SeqlistMaxSize 1000
typedef char SeqType;

typedef struct SeqListList{
	SeqListType data[SeqListMaxSize];
	size_t size;
}SeqList;

void SeqListInit(SeqList* seq);

void SeqListPushBack(SeqList* seqlist,SeqListType value);

void SeqListPushFront(SeqList* seqlist,SeqListType value);

void SeqListPopFront(SeqList* seqlist)

size_t SeqListFind(SeqList* seq,SeqType value);

void SeqListInsert(SeqList* seq,size_t pos,SeqListType value);

void SeqListErase(SeqList* seqlist,size_t pos);

seqlist.c

#include
#include"seqlist.h"

void SeqListInit(SeqList* seqlist){
	if(seqlist == NULL){
		return;
	}
	seqlist->size = 0;
}

void SeqListPushBack(SeqList* seqlist,SeqListType){
	if(seqlist == NULL){
		return;
	}
	if(seqlist->size >= SeqListMaxSize){
		return;
	}
	++seqlist->size;
	seqlist->data[seqlist->size] = value;
	return;
}
void SeqListPopBack(SeqList* seqlist){
	if(seqlist == NULL){
		return;
	}
	if(seqlist->size == 0){
		return;//kong shunxubiao
	}
	--seqlist->size;
}

void SeqListPushFront(SeqList* seqlist,SeqListType value){
	if(seqlist == NULL){
		return;
	}
	if(seqlist->size >= SeqlistMaxSize){
		return;
	}
	++seqlist->size;
	size_t i = seqlist->size -1;
	for(;i>0;i--){
		seqlist->data[i] = seqlist->data[i-1];
	}
	seqlist->data[0] = value;
	return;
}

void SeqListPopFront(SeqList* seqlist){
	if(seqlist == NULL){
		return;
	}
	if(seqlist->size == 0){
		return;//kongshunxubiao
	}
	size_t i = 0;
	for(;isize - 1;++i){
		seqlist->data[i] = seqlist->data[i+1];
	}
	--seqlist->size;
	return;
}

void SeqListInsert(SeqList* seqlist,size_t pos,SeqListType value){
	if(seqlist == NULL){
		return;
	}
	if(pos > seqlist->size){
		return;//pos yuejie pos->[0,pos]
	}
	if(seqlist->size >= SeqListMaxSize){
		return;//shunxubiao yijing manle
	}
	if(pos == 0 ){
		SeqListPushFront(seqlist,value);
		return;
	}
	++seqlist->size;
	size_t i = seqlist->size - 1;
	for(;i - 1 >= pos;--i){
		seqlist->data[i] = seqlist->data[i - 1];
	}
	seqlist->data[pos] = value;
	return;
}

void SeqListErase(SeqList* seqlist,size_t pos){
	if(seqlist == NULL){
		return;
	}
	if(seqlist->size == 0){
		return;
	}
	if(pos >= seqlist->size){
		return;//yuejie
	}
	size_t i = pos;
	for(;isize - 1;++i){
		seqlist->data[i] = seqlist->data[i+1];
	}
	--seqlist->size;
	return;
}

你可能感兴趣的:(数据结构-线性表)