#include<stdio.h> #include<stdlib.h> #define Maxsize 10 typedef int elementype; typedef struct { elementype v[Maxsize]; int length; }sqlist; int main() { sqlist *L; L = (sqlist *L)malloc(sizeof(sqlist)); int length(sqlist *L) L->length=0; printf("%d",length(L)); } int length(sqlist *L)//长度 { int length; length = L->length; return length; } int insert(sqlist *L;int i;elementype x)//i为插入元素的位序号,x为值。 { if(L->length==Maxsize) { printf("存储空间已满"); return 0; } else if(i<1||i>L->length+1) { printf("插入位置不对"); return 0; } else { for(j=L->length-1;j>i-1) { L->v[j+1]=L->v[j]; L->v[i-1]=x; //空出的下标 L->length=L->length+1; return 1; } } } int delete(sqlist *L,int i,elementype y) { int j; if((i<1)||i(>L->length))//超出范围 { printf("位置不对"); return 0; } else { *y=v[i-1]; for(j=i;j<L-<length;j++) { L->v[j-1]=L->v[j]; L->length=L->length-1; return 1; } } } int search(sqlist *L,int x) { int i; for(i=0;i<L->length;i++) { if(x==L-v[i]) break; } if(i<L->length) return i+1; else return 0; }