首页 > 用户发贴区 > 编程问题提问区 > 大家帮忙看看~
2007
06-24

分析以下算法的功能
1.
#define MAXNUM 100
typedef struct
{Elemtype List[MAXNUM];
 int length;
}seqlist;
int Insert(seqlist *L,int i,Elemtype x)
{
  int j;
  if(i<1||i>L->length+1)
    {printf(“Error!”);       
    return FALSE;}
  else 
    if(L->length>=MAXNUM)
    {printf(“overflow!”);
    return FALSE; }     
for (j=L->length;j>i-1;j–)
List[j]=List[j-1];     
List[i-1]=x;         
L->length++;      
return TRUE;}


 



2.
#define  maxsize  100  
 typedef struct             
 {          
int i,j;            
elemtype e;                
}Triple; 
Typedef  struct          
{  Triple data[maxsize+1];
   int mu,nu,tu;
}TSMatrix;
void TranposeSMatrix(TSMatrix M,TSMatrix &T)
{T.mu=M.nu;T.nu=M.mu;T.tu=M.,tu;
 if(T.tu)
{q=1;
 for(col=1;col<=M.nu;++col)
    (p=1;p<=M.tu;++p)
If(M.data[p].j= =col){
    T.data[q].i=M.data[p].j;T.ata[q].j=M.data[p].i;
    T.data[q].e=M.data[p].e;++q;}
}
return OK;
}



3.
#define max 50
int visited[max];
 typedef struct{
  char vexs[max];
  int arcs[max][max];
  int vexnum,arcnum;
}graph;
void creatgraph(graph *ga)
 {int i,j,k,w;
  char v1,v2;
  printf(“\ninput vexnum and arcnum”);
   scanf(“%d%d”,ga->vexnum,ga->arcnum);getchar();
 for(i=0;i<ga->vexnum;i++)
 {printf(“\ninput %dth vex(char) : “,i);
  scanf(“%c”,ga->vexs[i]);getchar();}
 for(i=1;i<=ga->vexnum;i++)
  for(j=1;j<=ga->vexnum;j++)
   ga->arcs[i][j]=0;
 for(k=1;k<=ga->arcnum;k++)
 {printf(“\ninput %dth vex(char) : “,k);
scanf(“%c%c%d”,&i,&j,&w);getchar();
  for(m=1;m<=ga->vexnum;m++)
   if(ga->vexs[m]==v1)
    {i=m;break;}
   for(m=1;m<=ga->vexnum;m++)
    {j=m;break;}
      ga->arcs[i][j]=ga->arcs[j][i]=w;
 }
}



4.
#define max 100
typedef truct{
int key;
}sselement;
typedef struct{
sselement elem[max];
int length;
}sstable;
typedef struct{
 int addr;
int index;
}idtable;
idtabble id[b];
int bhlock_search(sstable st,idtable id[],int key)
{int i,mid;
 int low1=0,hight1=b-1,low2,hight2;
while(low1<=hight1)
{ mid=(low1+hight1)/2;
 if(key<=id[mid].index) hight=mid-1;
 else low1=mid+1;
}
if(low1<b)
{low2=id[low1].addr;
if(low1==b-1)
hight2=st.length-1;
else
hight2=id[low1+1].addr-1;
}
for(i=low2;i<=high2;i++)
 if(st.elem[i].key==key)
return i;
return 0;
}


帮帮忙啊~急


大家帮忙看看~》有 1 条评论

  1. zhaoyuanpeng198 说:

    我也看不懂~~呵呵~~

     

留下一个回复