实习1600,转正大概3500-4000吧
# include
# define MaxSize 20
typedef struct seqlist
{
int elem[MaxSize];
int listlength;
}SeqList;
void InitList(SeqList*l)
{
l->listlength=0;
}
void Print(SeqList l)
{
int i;
for(i=0;i
}
int InList(SeqList l,int x)
{
int i=0;
while(i
if(i
return(i);
return(-1);
}
void InsList(SeqList * l,int x)
{
int i=0,j;
while(i
for(j=l->listlength-1;j>=i;--j)
l->elem[j+1]=l->elem[j];
l->elem[i]=x;
(l->listlength)++;
}
void DelList(SeqList*l,int i)
{
int j;
if (i<0||i>l->listlength-1)
{
printf("\nIndex error");
return;
}
for(j=i+1;j<=l->listlength-1;++j)
l->elem[j-1]=l->elem[j];
l->listlength--;
}
main()
{
SeqList list;
int index,element,x;
InitList(&list);
printf("Enter the value in the list:");
scanf("%d",&element);
printf("Enter the values in the list:");
while(element!=0)
{
InsList(&list,element);
scanf("%d",&element);
}
Print(list);
printf("\nEnter the value to be deleted:");
scanf("%d",&x);
index=InList(list,x);
if(index==-1)
printf("%d does not exit in the list.\n",x);
else
DelList(&list, index);
Print(list);
/*printf("\n");*/
}