データ構造の基本線形テーブル学習
2118 ワード
#define maxsize 100
typedef int elemtype;
typedef struct{
elemtype num[maxsize];
int length;
}List;
1.
( 0)
void Initlist(List L)
{
L.length=0;
}
2.
void clearlist(List L)
{
L.length=0;
}
3.
int emptylist(List L)
{
if(L.length=0)
return (1);
else
return(0);
}
4.
int lengthlist(List L)
{
return(L.length);
}
5.
elemtype getnum(List L)
{
if(i<0)||(i>length-1))
printf("position not exsit");
else
return(L.num(i-1));
}
6.
int locatnum(List L,elemtype x)
{
int i,flag=1;
for(i=0;i<=L.length;i++)
if(L.num[i]==x)
{
flag=0;
return(1+i);
break;
}
if(flag)
return(-1);
}
7.
int insertnum(List L,elemtype x,int p)
{
int j:
if(L.length ==maxsize)
printf("List overflow")
else if (p>0)||(p>L.length))
printf("position not exist")
else if(L.length[p]==x)
{
return(-1)
;break;
}
else
for(j=L.length;j>=p;j--)
L.num[j+1]=L.num[j];
L.num[p]=x;
L.length++;
return(1);
}
8.
int deletenum(List L,int p)
{
int j;
if(L.length==0)
printf("List underflow")
else if ((p<0)||(p>L.length))
{
printf("position not exist
");
retuan(-1);
}
else
for(j=p+1;j<=L.length;j++)
L.num[j-1]=L.num[j];
L.length--;
return(1);
}
9.
priornum(List L,elemtype x)
{
int i;
i=locatnum(L,x)-1;
if(i>=1)
return(L.num[i-1]);
else
printf("priornum not exist")
;
}
10.
nextnum(List L,elemtype x)
{
int i;
i=locatnum(L,x)+1;
if((i>0)&&(i=list2.length)&&(list2.length>0))
for (j=0;j<=list2.length;j++)
list1.num[list1.length+j+1]=list2.num[j];
else
if(((maxsize-list1.length)0)&&(list.length>0))
{
p=maxsize-list1.length;
for(j=0;j<=p;j++)
list1.num[list1.length+j+1]=list2.num[j];
}
else
printf("list not cater")
return (&list1);
}