线性表的插入删除
#include"stdio.h"#include"stdlib.h"
int*inistl(int m,int *n)
{int*v=NULL;
v=malloc(m*sizeof(int*));
n=0;
return v;
}
void insl(int*v,int m,int*n,int i,int b)
{
int j;
if(*n>=m)
{printf("the stack is overflow\n");
return;
}
if(i>*n-1) i=*n+1;
if(i<1) i=1;
for(j=*n;j>=i;j--)
v[j]=v[j-1];
v[i-1]=b;
*n=*n+1;
}
void desl(int*v,int m,int*n,int i)
{int j;
if(*n==0)
{printf("the stack is underflow\n ");
return;
}
if((i<1)||(i>*n))
{printf("not this element in the list!\n");
return;
}
for (j=i;j<=*n-1;j++)
v[j-1]=v[j];
*n=*n-1;
return;
}
void input(int*v,int n)
{int i;
for(i=0;i<n;i++)
scanf("%d",v+i);
}
void output(int*v,int n)
{int i;
for(i=0;i<n;i++)
printf("%d",*(v+i));
}
serch(int*v,int n,int x)
{int k;
k=0;
while ((k<n)&&(v[k]=!x)) k=k+1;
if (k==n) k=-1;
return(k);
}
bserch(int*v,int n,int x)
{ int i,j,k;
i=1; j=n;
while (i<=j)
{ k=(i+j)/2;
if (v[k-1]==x) return(k-1);
if (v[k-1]>x) j=k-1;
else i=k+1;
}
return(-1);
}
bubsort(int v[],int n)
{ int m,k,j,i,d; k=0;
m=n-1; while (k<m)
{ j=m-1; m=0;
for(i=k;i<=j;i++)
if (v[i]>v[i+1])
{d=v[i];v[i]=v[i+1];v[i+1]=d;m=i;}
j=k+1; k=0;
for (i=m;i>=j;i--)
if (v[i-1]>v[i])
{d=v[i];v[i]=v[i-1];v[i-1]=d;k=i;}
}
return(i);
}
qksort1(int p[],int m,int n)
{ int split(p,m,n) ;
int i;if (n>m)
{
i=split(p,m,n);
qksort1(p,m,i-1);
qksort1(p,i+1,n);
}
return(i);}
int split(p,m,n) ;
int m,n, p[];
{ int i,j,k,u,t;
i=m; j=n;k=(i+j)/2;
if ((p[i]>=p[j])&&(p[j]>=p[k])) u=j;
else if ((p[i]>=p[k])&&(p[k]>=p[j])) u=k;
else u=i;
t=p[u]; p[u]=p[i];
while (i!=j)
{ while ((i<j)&&(p[j]>=t)) j=j-1;
if (i<j){ p[i]=p[j]; i=i+1;
while ((i<j)&&(p[i]<=t)) i=i+1;
if (i<j)
{p[j]=p[i]; j=j-1;}
}
p[i]=t;
return(i);
}
void main()
{int *v,m,*n,i,b,x,y,k;
n=(int *)malloc(sizeof(int));
printf("请输入线性表容量:");
scanf("%d",&m);
v=inistl(m,n);
printf("请输入线性表实际个数:");
scanf("%d",n);
printf("请输入线性表起始元素:");
input(v,*n);
printf("请输入线性表插入点位置:");
scanf("%d",&i);
printf("请输入线性表插入元素:");
scanf("%d",&b);
insl(v,m,n,i,b);
printf("输出操作后线性表:");
output(v,*n);
printf("\n");
printf("请输入线性表删除点位置:");
scanf("%d",&i);
desl(v,m, n, i);
printf("输出操作后线性表:");
output(v,*n);
printf("\n");
printf("请输入要查找的元素:");
scanf("%d",&x);
printf("\n");
printf("please put choose 1 is search 2 is bsearch\n");
scanf("%d",&y);
switch(y)
{case 1:k=serch(v,*n,x);
case 2:k=bserch(v,*n,x);}
if(k==-1)
printf("not find the element in line!\n");
else printf("the element in the line is %d\n",++k);
}
想实现线性表的删除插入功能 哪里出错了 急啊