и алгоритм, выполняемый над ней
Тип структуры данных и алгоритм, выполняемый над ней (или вид итератора).
// 1-------------------------------------------------------
int F(double *p[])
{ int n;
for (n=0; p[n]!=NULL; n++);
return(n); }
// 2-------------------------------------------------------
void F(double *p[])
{ int i,k;
do {
k=0;
for (i=1; p[i]!=NULL; i++)
if (*p[i-1] > *p[i])
{ double *dd;
dd=p[i]; p[i]=p[i-1]; p[i-1]=dd; k++;
}
} while(k);
}
// 3-------------------------------------------------------
void F(double *p[], double *q)
{ int i,n;
for (i=0; p[i]!=0; i++)
if (*p[i] > *q) break;
for (n=i; p[n]!=NULL; n++);
for (; n >=i; n--)
p[n+1] = p[n];
p[i] = q;
}
// 4-------------------------------------------------------
int F(double **p[])
{ int k,i,j;
for (k=i=0; p[i]!=NULL; i++)
for (j=0; p[i][j] !=NULL; j++, k++);
return(k);
}
// 5-------------------------------------------------------
char **F(char a[][80], int n)
{ int i; double **p;
p = malloc((n+1)*sizeof(char*));
for (i=0; i<n; i++) p[i]=a[i];
p[n]=NULL;
return(p);
}
// 6-------------------------------------------------------
// strlen(char *) - длина строки
char *F(char *p[])
{ int i,sz,l,k;
for (i=sz=k=0; p[i]!=NULL; i++)
if ((l=strlen(p[i])) >sz) { sz=l; k=i; }
return(p[k]);
}
// 7-------------------------------------------------------
char **F(char c[])
{ char **p; int i,n, cnt;
p = malloc(20 * sizeof(char*));
for (i=n=cnt=0; c[n]!=0; n++)
{
if (c[n]==' ')
{ c[n]='\0'; cnt=0; }
else
{
cnt++;
if (cnt==1) p[i++]=&c[n];
if (i==19) break;
}
}
p[i]=NULL; return(p);
}
// 8-------------------------------------------------------
char *F(char *p[], int m)
{ int n; char *q;
for (n=0; p[n]!=NULL; n++);
if (m >=n) return (NULL);
q = p[m];
for (n=m; p[n]!=NULL; n++) p[n]=p[n+1];
return(q);
}
// 9-------------------------------------------------------
// strcmp(char*,char*) - сравнение строк
int F(char *p[], char *str)
{ int h,l,m;
for (h=0; p[h]!=NULL; h++);
for (h--,l=0; h >= l;)
{
m = (l+h) / 2;
switch(strcmp(p[m],str))
{
case 0: return(m);
case -1: l = m+1; break;
case 1: h = m-1; break;
}
}
return(-1);
}
// 10-------------------------------------------------------
// gets(char *) - ввод строки с клавиатуры
char **F()
{ int n; char **p, s[80];
p = malloc(100 * sizeof(char*));
for (n=0; n< 99 & (gets(s),s[0]!='\0'); n++ )
{
p[n]=malloc(strlen(s)+1);
strcpy(p[n],s);
}
p[n]=NULL; return(p);
}
// 11-------------------------------------------------------
void F(char *p[], int m)
{ int n; char *q;
for (n=0; p[n]!=0; n++);
if (m >= n) return;
for (; n > m; n--) p[n+1] = p[n];
p[m+1] = malloc(strlen(p[m]+1));
strcpy(p[m+1],p[m]);
}
// 12-------------------------------------------------------
char *F(char **p[], int n)
{ int k,i,j;
for (k=i=0; p[i]!=NULL; i++)
for (j=0; p[i][j] !=NULL; j++, k++)
if (k==n) return(p[i][j]);
return(NULL);
}
// 13--------------------------------------------------------
struct xxx { int v; xxx *next; };
int F(xxx *p)
{ int n;
for (n=0; p!=NULL; p=p->next, n++);
return(n);
}
// 14---------------------------------------------------------
struct xxx { int v; xxx *next; };
void F(xxx **p, int v)
{ xxx *q;
q = malloc(sizeof(xxx));
q->val = v; q->next = *p; *p = q;
}
// 15---------------------------------------------------------
struct xxx { int v; xxx *next; };
xxx *F(xxx *p, int n)
{
for (; n!=0 && p!=NULL; n--, p=p->next);
return(p);
}
// 16--------------------------------------------------------
struct xxx { int v; xxx *next; };
void F( xxx **p, int v)
{ xxx *q;
q = malloc(sizeof( xxx));
for ( ; *p !=NULL; p = &(*p)->next);
q->val = v; q->next = NULL; *p = q;
}
// 17--------------------------------------------------------
void F( xxx **p, int n)
{ xxx *q;
for (; n!=0 && *p!=NULL; n--, p =&(*p)->next);
q = *p;
if (*p != NULL) *p = (*p)->next;
free (q);
}
// 18---------------------------------------------------------
int F( xxx *p)
{ int n; xxx *q;
if (p==NULL) return(0);
for (q = p, p = p->next, n=1; p !=q; p=p->next, n++);
return(n);
}
// 19---------------------------------------------------------
struct xxx { int v; xxx *next,*pred; };
void F( xxx **p, int v)
{ xxx *q;
q = malloc(sizeof( xxx));
q->val = v; q->next = q->pred = q;
if (*p == NULL) *p = q;
else
{
q->next = *p; q->pred = (*p)->pred;
(*p)->pred->next = q; (*p)->pred = q; *p=q;
}
}
// 20--------------------------------------------------------
struct xxx { int v; xxx *next; };
void F( xxx **ph)
{ xxx *q, *tmp, **pp;
tmp = NULL;
while (*ph !=NULL)
{
q = *ph; *ph = (*ph)->next;
for (pp = &tmp; *pp !=NULL && (*pp)->val < q->val;
pp = &(*pp)->next);
q->next = *pp; *pp = q;
}
*ph = tmp;
}
// 21--------------------------------------------------------
struct xxx { int v; xxx *next,*pred; };
xxx *F( xxx **pp, int n)
{ xxx *q;
for (q = *pp; n!=0; q = q->next, n--);
if (q->next == q) { *pp = NULL; return(q); }
if (q == *pp) *pp = q->next;
q->pred->next = q->next;
q->next->pred = q->pred;
return(q);
}
// 22--------------------------------------------------------
struct xxx { int v; xxx *p[4]; };
int F(xxx *q)
{
int i,n,m;
if (q==NULL) return 0;
for (n=F1(q->p[0]),i=1; i< 4; i++)
if ((m=F(q->p[i])) >n) n=m;
return n+1;
}
// 23--------------------------------------------------------
struct xxx { int v; xxx *l,*r; };
int F( xxx *p)
{
if (p==NULL) return(0);
return (1 + F(p->r) + F(p->l));
}
// 24--------------------------------------------------------
struct xxx
{
int val,cnt;
xxx **link;
};
int F(xxx *p)
{ int i,n;
p->cnt++;
for (i=0, n=1; p->link[i] !=NULL; i++)
if (p->link[i]->cnt != p->cnt)
n += F(p->link[i]);
return (n);
}
// 25--------------------------------------------------------
void F(int a[], int n, int v)
{
if (a[n] ==-1) { a[n]=v; return; }
if (a[n]==v) return;
if (a[n] >v)
F(a,2*n,v);
else
F(a,2*n+1,v);
}
void z3() {
int B[256],i;
for (i=0; i< 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 && p==dst) return (0);
for (i=0, n=-1; p->link[i] !=NULL; i++)
if (p->link[i] !=from)
{
m = F(p->link[i],dst,p);
if (m > 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 > 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 <=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->next)
(*pf)(q->data);
}
// 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->next)
for ( q = p->ph; q!=NULL; q=q->next)
(*pf)(q->data);
}
// 32--------------------------------------------------------
struct mxxx { void **data; mxxx *next; };
void F( mxxx *p, void (*pf)(void*))
{
void **q;
for (; p != NULL; p = p->next)
for (q = p->data; *q != NULL; q++)
(*pf)(*q);
}
// 33--------------------------------------------------------
void F(void ***p, void (*pf)(void*))
{
void **q;
for (; *p != NULL; p++)
for (q = *p; *q != NULL; q++)
(*pf)(*q);
}
// 34--------------------------------------------------------
void F(void *p, int sz, int n, void (*pf)(void*))
{
char *q;
for (q = p; n > 0; n--, q+=sz)
(*pf)(q);
}
// 35--------------------------------------------------------
struct xxx { void *data; xxx **link; };
void F( xxx *p, void (*pf)(void*))
{
xxx **q;
if (p==NULL) return;
(*pf)(p->data);
for (q = p->link; *q != NULL; q++)
F(*q,pf);
}
// 36--------------------------------------------------------
struct xxx { void **data; xxx *r, *l; };
void F( xxx *p, void (*pf)(void*))
{
void **q;
if (p==NULL) return;
F(p->r, pf);
for (q = p->data; *q != NULL; q++)
(*pf)(*q);
F(p->l, pf);
}
// 37-------------------------------------------------------
struct xxx { void *data; xxx *next; };
struct zzz { xxx *ph; zzz *r, *l; };
void F( zzz *p, void (*pf)(void*))
{
xxx *q;
if (p==NULL) return;
F(p->r, pf);
for (q = p->ph; q != NULL; q = q->next)
(*pf)(q->data);
F(p->l, pf);
}
// 38-------------------------------------------------------
struct xxx { void *data; xxx *next,*pred; };
void F( xxx *p, void (*pf)(void*))
{
xxx *q;
if (p==NULL) return;
q = p;
do {
(*pf)(q->data);
q = q->next;
} while (q != p);
}
// 39-------------------------------------------------------
void F(void ***p, int (*pf)(void*))
{
int i,j;
for (i =0; p[i] != NULL; i++)
for (j =0; p[i][j] != NULL; j++)
if ((*pf)(p[i][j])) return p[i][j];
return NULL;
}
// 40--------------------------------------------------------
struct xxx { int v; xxx **pp; };
int F(xxx *q)
{
int i,n,m;
if (q==NULL) return 0;
for (n=F(q->p[0]),i=1; q->p[i]!=NULL; i++)
if ((m=F(q->p[i])) >n) n=m;
return n+1;
}
// 41---------------------------------------------------------
typedef int (*PCMP)(void*, void*);
struct xxx { void *data; xxx *next; };
void *F( xxx **p, PCMP pf)
{
xxx *q;
void *s;
for (s=p[0]->data; *p != NULL; p++)
for (q = *p; q != NULL; q = q->next)
if ((*pf)(s,q->data)==-1) s=q->data;
return s;
}
// 42--------------------------------------------------------
typedef int (*PCMP)(void*, void*);
struct xxx { void *data; xxx *next; };
struct sxxx { xxx *ph; sxxx *next; };
void *F( sxxx *p, PCMP pf)
{
xxx *q;
vois *s;
for (s=p->ph->data; p != NULL; p = p->next)
for ( q = p->ph; q!=NULL; q=q->next)
if ((*pf)(s,q->data))==-1) s=q->data;
return s;
}
// 43--------------------------------------------------------
typedef int (*PCMP)(void*, void*);
struct xxx { void **data; xxx *next; };
void *F( mxxx *p, PCMP pf)
{
void **q;
void *s;
for (s=p->data[0]; p != NULL; p = p->next)
for (q = p->data; *q != NULL; q++)
if ((*pf)(s,*q)==-1) s = *q;
return s;
}
// 44--------------------------------------------------------
typedef int (*PCMP)(void*, void*);
void *F(void ***p, PCMP pf)
{
void **q, *s;
for (s=p[0][0]; *p != NULL; p++)
for (q = *p; *q != NULL; q++)
if ((*pf)(s,*q)==-1) s = *q;
return s;
}
// 45--------------------------------------------------------
typedef int (*PCMP)(void*, void*);
void *F(void *p, int sz, int n, PCMP pf)
{
char *q;
void *s;
for (q = p, s = p; n > 0; n--, q+=sz)
if ((*pf)(s,q)==-1) s=q;
return s;
}
// 46--------------------------------------------------------
typedef int (*PCMP)(void*, void*);
struct xxx { void *data; xxx **link; };
void *F( xxx *p, void PCMP pf)
{
xxx **q;
void *s,*r;
if (p==NULL) return NULL;
s = p->data;
for (q = p->link; *q != NULL; q++)
{
r=F(*q,pf);
if (r!=NULL && (*pf)(s,r)==-1) s=r;
}
return r;
}
// 47--------------------------------------------------------
typedef int (*PCMP)(void*, void*);
struct xxx { void *data; xxx *next,*pred; };
void *F( xxx *p, PCMP pf)
{
xxx *q;
void *s;
if (p==NULL) return NULL;
q = p; s = p->data;
do {
if ((*pf)(s,q->data))==-1) s=q->data;
q = q->next;
} while (q != p);
return s;
}
// 48---------------------------------------------------------
typedef int (*PCMP)(void*, void*);
void F(void *p[], void PCMP pf)
{
int i,k;
do {
k=0;
for (i=1;p[i]!=NULL; i++)
if ((*pf)(p[i-1],p[i] > 0))
{ void *s = p[i-1];
p[i-1]=p[i];
p[i]=s; k++;
}
} while(k);
}
// 49---------------------------------------------------------
typedef int (*PCMP)(void*, void*);
void F(void *p[], void PCMP pf, void *q)
{ int i,j;
for (i=0; p[i]!=NULL && (*pf)(p[i],q) < 0; i++);
for (j=0; p[j]!=NULL; j++);
for (; j>=i; j--) p[j+1]=p[j];
p[i]=q;
}
// 50---------------------------------------------------------
typedef int (*PCMP)(void*, void*);
struct xxx { void *data; xxx *next; };
void F( xxx **p, PCMP pf, void *q)
{
xxx *s;
for (; *p!=NULL && (*pf)((*p)->data,q) < 0; p = &(*p)->next);
s = new xxx;
s->data = q;
s->next = (*p)->next;
*p = s;
}
// ---------------------------------------------------------