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

       

и алгоритм, выполняемый над ней




Тип структуры данных и алгоритм, выполняемый над ней (или вид итератора).



// 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] &#62 *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] &#62 *q) break;
for (n=i; p[n]!=NULL; n++);
for (; n &#62=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&#60n; 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])) &#62sz) { 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++]=&#38c[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 &#62=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 &#62= 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&#60 99 &#38 (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 &#62= n) return;
for (; n &#62 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-&#62next, n++);
return(n);
}
// 14---------------------------------------------------------

struct xxx { int v; xxx *next; };
void F(xxx **p, int v)
{ xxx *q;
q = malloc(sizeof(xxx));
q-&#62val = v; q-&#62next = *p; *p = q;
}
// 15---------------------------------------------------------

struct xxx { int v; xxx *next; };
xxx *F(xxx *p, int n)
{
for (; n!=0 &#38&#38 p!=NULL; n--, p=p-&#62next);
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 = &#38(*p)-&#62next);
q-&#62val = v; q-&#62next = NULL; *p = q;
}
// 17--------------------------------------------------------

void F( xxx **p, int n)
{ xxx *q;
for (; n!=0 &#38&#38 *p!=NULL; n--, p =&#38(*p)-&#62next);
q = *p;
if (*p != NULL) *p = (*p)-&#62next;
free (q);
}
// 18---------------------------------------------------------




int F( xxx *p)
{ int n; xxx *q;
if (p==NULL) return(0);
for (q = p, p = p-&#62next, n=1; p !=q; p=p-&#62next, n++);
return(n);
}
// 19---------------------------------------------------------

struct xxx { int v; xxx *next,*pred; };
void F( xxx **p, int v)
{ xxx *q;
q = malloc(sizeof( xxx));
q-&#62val = v; q-&#62next = q-&#62pred = q;
if (*p == NULL) *p = q;
else
{
q-&#62next = *p; q-&#62pred = (*p)-&#62pred;
(*p)-&#62pred-&#62next = q; (*p)-&#62pred = 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)-&#62next;
for (pp = &#38tmp; *pp !=NULL &#38&#38 (*pp)-&#62val &#60 q-&#62val;
pp = &#38(*pp)-&#62next);
q-&#62next = *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-&#62next, n--);
if (q-&#62next == q) { *pp = NULL; return(q); }
if (q == *pp) *pp = q-&#62next;
q-&#62pred-&#62next = q-&#62next;
q-&#62next-&#62pred = q-&#62pred;
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-&#62p[0]),i=1; i&#60 4; i++)
if ((m=F(q-&#62p[i])) &#62n) 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-&#62r) + F(p-&#62l));
}
// 24--------------------------------------------------------

struct xxx
{
int val,cnt;
xxx **link;
};
int F(xxx *p)
{ int i,n;
p-&#62cnt++;
for (i=0, n=1; p-&#62link[i] !=NULL; i++)
if (p-&#62link[i]-&#62cnt != p-&#62cnt)
n += F(p-&#62link[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] &#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)


(*pf)(q-&#62data);
}
// 32--------------------------------------------------------

struct mxxx { void **data; mxxx *next; };
void F( mxxx *p, void (*pf)(void*))
{
void **q;
for (; p != NULL; p = p-&#62next)
for (q = p-&#62data; *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 &#62 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-&#62data);
for (q = p-&#62link; *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-&#62r, pf);
for (q = p-&#62data; *q != NULL; q++)
(*pf)(*q);
F(p-&#62l, 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-&#62r, pf);
for (q = p-&#62ph; q != NULL; q = q-&#62next)
(*pf)(q-&#62data);
F(p-&#62l, 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-&#62data);
q = q-&#62next;
} 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-&#62p[0]),i=1; q-&#62p[i]!=NULL; i++)
if ((m=F(q-&#62p[i])) &#62n) 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]-&#62data; *p != NULL; p++)
for (q = *p; q != NULL; q = q-&#62next)
if ((*pf)(s,q-&#62data)==-1) s=q-&#62data;
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-&#62ph-&#62data; p != NULL; p = p-&#62next)
for ( q = p-&#62ph; q!=NULL; q=q-&#62next)
if ((*pf)(s,q-&#62data))==-1) s=q-&#62data;
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-&#62data[0]; p != NULL; p = p-&#62next)
for (q = p-&#62data; *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 &#62 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-&#62data;
for (q = p-&#62link; *q != NULL; q++)
{
r=F(*q,pf);


if (r!=NULL &#38&#38 (*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-&#62data;
do {
if ((*pf)(s,q-&#62data))==-1) s=q-&#62data;
q = q-&#62next;
} 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] &#62 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 &#38&#38 (*pf)(p[i],q) &#60 0; i++);
for (j=0; p[j]!=NULL; j++);
for (; j&#62=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 &#38&#38 (*pf)((*p)-&#62data,q) &#60 0; p = &#38(*p)-&#62next);
s = new xxx;
s-&#62data = q;
s-&#62next = (*p)-&#62next;
*p = s;
}
// ---------------------------------------------------------




Содержание раздела