#单链表
#include <stdio.h> #include <stdlib.h> #include<malloc.h> #define MaxSize 30 typedef struct{ int data[MaxSize]; int length; }SeqList; void initList(SeqList*L){ L->length = 0; } int Length(SeqList*L) { return (L->length); } void show(SeqList*L){ int i; if (L->length==0) printf("表为空\n"); else{ for( i =0; i<L->length;i++) printf("%d ",L->data[i]); } } int Locate(SeqList*L,int x){ int i; for( i = 0;i<L->length;i++) if (L->data[i]==x) return i+1; return 0; } int getElement(SeqList *L,int x){ if(x<1&&x>L->length){ printf("输入位置有误") } return L->data[x]; } void Insert(SeqList*L,int i,int x){ int j; if(L->length == MaxSize) printf("表已满,请重试\n"); else if(i<1||i>L->length+1) printf("插入位置有误,请重试\n"); else{ for(j = L->length;j>=i-1;j--){ L->data[j] = L->data[j-1]; } L->data[i-1] = x; L->length++; } } void Delete(SeqList*L,int i,int x){ int j; if(i<1||i>L->length+1) printf("超出范围\n"); else for(j = i;j<L->length-1;j++) data[j] = data[j+1]; L->length--; } int main(){ SeqList*L; L = initList(L); }