静态顺序表
1 #include <cstdio> 2 #include <windows.h> 3 #define MaxSize 10 4 void insertElem(int Sqlist[],int *len,int i,int x) 5 { 6 int t; 7 if(*len==MaxSize || i<1 || i>*len+1) //检测非法插入 8 { 9 printf("This insert is illegal\n"); 10 return; 11 } 12 for(t=*len-1;t>=i-1;t--) 13 Sqlist[t+1]=Sqlist[t]; 14 Sqlist[i-1]=x; //插入 15 *len=*len+1; //表长+1 16 } 17 18 void DelElem(int Sqlist[],int *len,int i) 19 { 20 int j; 21 if(i<1 || i>*len) 22 { 23 printf("This delet is illegal\n"); 24 return; 25 } 26 for(j=i;j<=*len-1;j++) 27 Sqlist[j-1]=Sqlist[j]; 28 *len=*len-1; 29 } 30 int main() 31 { 32 int Sqlist[MaxSize]; 33 int len; 34 int i; 35 for(i=0;i<6;i++) 36 scanf("%d",&Sqlist[i]); 37 len=6; 38 for(i=0;i<len;i++) 39 printf("%d ",Sqlist[i]); 40 printf("\nThe spare length is %d\n",MaxSize-len); 41 42 insertElem(Sqlist,&len,3,0); 43 for(i=0;i<len;i++) 44 printf("%d ",Sqlist[i]); 45 printf("\nThe spare length is %d\n",MaxSize-len); 46 47 insertElem(Sqlist,&len,11,0); 48 DelElem(Sqlist,&len,6); 49 for(i=0;i<len;i++) 50 printf("%d ",Sqlist[i]); 51 printf("\nThe spare length is %d\n",MaxSize-len); 52 53 system("pause"); 54 return 0; 55 }
——现在的努力是为了小时候吹过的牛B!!