当前位置:简历谷 >

面试 >面试笔试 >

笔经A

笔经A

笔经A
笔经A
笔试题有A,B两个非继承关系的类,现有一函数void fun(A&)用什么方法可以把一个非常量类B传递给fun?
排序及查找方法
include
include
define N 11
/*用监视哨查找*/
int search(int array[],int n,int k)
{int i;
i=n-1;
array[0]=k;
while(array[i]!=k) i--;
return(i);
}
/*折半查找法*/
int halfsearch(int array[],int n,int k)
{int i,j,mid;
i=1;j=n;
while(i<=j)
{mid=(i+j)/2;
if(k==array[mid]) return(mid);
else if(kelse i=mid+1;
}
return(0);
}
/*冒泡排序法*/
void mpsort(int array[])
{int i,j,a;
a=0;
for(i=1;ifor(j=i+1;jif(array[i]>array[j])
{a=array[i];
array[i]=array[j];
array[j]=a;}
} /*直接插入排序*/
void insertsort(int array[])
{int i,j;
for(i=2;i{array[0]=array[i];
j=i-1;
while(array[0]{array[j+1]=array[j--];
array[j+1]=array[0];
}
}
}
/*建立*/
void creat(int array[])
{int i;
printf("enter the array:");
for(i=1;iscanf("%d",&array[i]);
}
/*显示*/
void print(int array[])
{int i;
printf("The numbers after sort is:");
for(i=1;iprintf("%d ",array[i]);
printf("");
}
main()
{int a[11],i,x,chang;
/*printf("enter the array");
for(i=1;i<11;i++)
scanf("%d",&a[i]);*/
aga:
printf("chang:1: use watching method finding
2:use half method finding
3: use directness intsert method sort
4:use bubble up method sort
5:exit");
scanf("%d",&chang);
switch (chang)
{case 1:
{creat(a);
printf("Please int the search number:");
scanf("%d",&x);
printf("The number station is:%d",search(a,N,x));
goto aga;
}
case 2:
{ creat(a);
insertsort(a);
print(a);
printf("Please int the search number:");
scanf("%d",&x);
printf("The number station is:%d",halfsearch(a,N,x));
goto aga;
}
case 3:
{creat(a);
insertsort(a);
print(a);
goto aga;
}
case 4:
{creat(a);
mpsort(a);
print(a);
goto aga;
}
case 5:{ printf("exit!");break;}
default:{printf("Error!"); goto aga;}
}
}
二、线性链表的存储实现 struct LNODE{
ElemType data;
struct LNODE *next;
};
typedef struct LNODE LNode;
typedef struct LNODE * LinkList;
1初始化操作
Status Init_L(LinkList L){
if (L=(LinkList *)malloc(sizeof(LNode)))
{L->next=NULL;return 1;}
else return 0;
}
2插入操作
Status ListInsert_L(LinkList &L,int i,ElemType e){
p=L,j=0;
while(p&&jnext;++j;}
标签: 笔经
  • 文章版权属于文章作者所有,转载请注明 https://jianligu.com/ms/bishi/ooenm.html
专题