数据结构——顺序表-删除算法

#include
#include 
#define SIZE  100
#define  INCREMENT_SIZE 10

typedef struct{
	int *elem; 
	int length;
	int listsize;
}Sqlist;

bool InintList_Sq(Sqlist &L){
	L.elem = (int*)malloc(SIZE*sizeof(int));
	if(!L.elem)
		return false;
	L.length = 0;
	L.listsize = SIZE;
	return true;
}

bool Delete(Sqlist &L,int pos,int &data){
	int *newbase;
	if(pos < 1||pos > L.length+1)
		return false;
	int *q = &L.elem[pos-1];
	data = *q;
	for(int *p=q;p<&L.elem[L.length-1];p++)
		*(p) = *(p+1);
	L.length--;
	return true;
}
int main(){
	int pos;int data;
	Sqlist sql;
	InintList_Sq(sql);
	printf("请输入输入数据的个数:"); 
	scanf("%d",&sql.length);
	for(int i=0;i

 

你可能感兴趣的:(考研数据结构代码,c++,数据结构)