Информатика и технология программирования


Тест 2 - часть 4



void F(int a[], int n, int v)
{
if (a[n] ==-1) { a[n]=v; return; }
if (a[n]==v) return;
if (a[n] &#62v)
F(a,2*n,v);
else
F(a,2*n+1,v);
}
void z3() {
int B[256],i;
for (i=0; i&#60 256; i++) B[i]=-1;
F(B,1,5); F(B,1,3); } // Пример вызова



// 26-------------------------------------------------------


struct xxx
{
int val,cnt;
xxx **link;
};
int F(xxx *p, xxx *dst, xxx *from)
{ int i,n,m;
if (from==NULL &#38&#38 p==dst) return (0);
for (i=0, n=-1; p-&#62link[i] !=NULL; i++)
if (p-&#62link[i] !=from)
{
m = F(p-&#62link[i],dst,p);
if (m &#62 n) n = m;
}
if (n !=-1) n++;
return (n);
}
void z4()
{
xxx *ph; int n;
n = F(ph,ph,NULL); } // Пример вызова


// 27--------------------------------------------------------


typedef int (*PCMP)(void*, void*);
void F(void **p, PCMP pf, void *q)
{ int n,i;
for (n=0; p[n]!=NULL; n++)
if ((*pf)(q,p[n]) ==1) break;
for (i=n; p[i] !=NULL; i++);
for (; i &#62 n; i--) p[i+1]=p[i];
p[n]=q;
}
// 28------------------------------------------------------


typedef int (*PCMP)(void*, void*);
void *F(void *p[], PCMP pf, void *q)
{ int h,l,m;
for (h=0, p[h]!=NULL; h++);
for (h--, l=0; l &#60=h;)
{
m = (h+l)/2;
switch ((*pf)(q, p[m]))
{
case 0: return(p[m]);
case -1: h = m-1; break;
case 1: l = m+1; break;
}
}
return(NULL);
}
// 29------------------------------------------------------


typedef int (*PTEST)(void*);
void *F(void *p, int sz, int n, PTEST pf)
{ char *q;
for (q=p; n!=0; q +=sz, n--)
if ((*pf)(q)) return(q);
return(NULL);
}
// 30---------------------------------------------------------


struct xxx { void *data; xxx *next; };
void F( xxx **p, void (*pf)(void*))
{
xxx *q;
for (; *p != NULL; p++)
for (q = *p; q != NULL; q = q-&#62next)
(*pf)(q-&#62data);
}
// 31--------------------------------------------------------


struct xxx { void *data; xxx *next; };
struct sxxx { xxx *ph; sxxx *next; };
void F( sxxx *p, void (*pf)(void*))
{
xxx *q;
for (; p != NULL; p = p-&#62next)
for ( q = p-&#62ph; q!=NULL; q=q-&#62next)



Начало  Назад  Вперед