Вы находитесь на странице: 1из 10

15.

14.1 14.2 ( 14).


.
(. . 14.1)
.
.

14.3.
:

inic_kuchi ();

15.1. (
i *i) (. 15.1).
)

i = i->uk;

i = uk[i];

i = i + 1; i - .
...

i->uk
...

...

uk[i]
...

i
) : i = i+1;

) : i = i->uk;

( i = uk[i];)

. 15.1.

15.2. p
)

p = NULL;

p = NOL;

15.3. *i
nov_id.
)
i =(struct el_sp *) malloc (sizeof(struct el_sp)); /*
if (i != NULL)
/*
*/
strcpy(i->id, nov_id);
/*
*/
else ...
/* */

*/

)
i = nov_el();
/*
if (i != NOL)
/*
strcpy (zn[i] , nov_id);
/*
else ...
/*

*/
*/
*/
*/

15.4. e *i (
):
)
free (i);

)
osvob(i);

15.5. *j p
(. 15.2):
j->uk = p;
p = j;

/* *j p */
/* *j
*/

...

1, 2 -
*j
. 15.2. *j p
.
2

15.6. *j *i
(. 15.3). 15.5 p i->uk:
i
*i
...

...

1, 2 -
*j
. 15.3. *j *i

j->uk = i->uk;
i->uk = j;

/* *j *i
/* *j *i

*/
*/

, *i
.
15.7. p:
if (p != NULL)
{ j = p;
p = p->uk;
free(j);
}
else ...

/* C
/* -
/* p
/* *j

*/
*/
*/
*/

/* :

*/

15.8. *i (
15.7 p i->uk):
if (i->uk != NULL)
/* *i
{ j = i->uk;
/* *i
i->uk = i->uk->uk;
/* *i
free (j);
/*
}
else ...
/*
(
, ), .
3

*/
*/
*/
*/
*/
,

15.9. p ( )
:
i = p;
while (i != NULL)
/* *i ( )
{...
/* *i
i = i->uk;
/*
}
for:

*/
*/
*/

for (i = p; i != NULL; i = i->uk)


. . . /* *i */

15.1. n .
8 .
.
:
n=7
.-:
SIMV
X
A1
SL
Z20
A
TEXT

:
A
A1
SIMV
SL
TEXT
X
Z20

15.1

,
. . 15.4 ,
.
.
t_id

gets().

strcmp(),
0, ,
4

, .
, < 0,

,
> 0 .

. 15.4.
strcpy() ,
: , , ,
.
15.1:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define MAXDL 9

/* . - (
'\0' )
*/

struct EL_SP
/* */
{ char id [MAXDL];
/* */
struct EL_SP *sled;
/* */
5

};
/*-------------------------------------------------------------------------------*/
/* */
/*-------------------------------------------------------------------------------*/
void Vkl ( struct EL_SP **p, char t_id[] )
/* . : *p -
,
t_id - () - */
/* . : *p
*/
{ struct EL_SP *pt,
/* - */
*k,*j;
/*

*/
/* - */
pt = (struct EL_SP *) malloc(sizeof(struct EL_SP));
strcpy(pt->id, t_id);
if (*p==NULL || strcmp(pt->id,(*p)->id) < 0)
{ /* - */
pt->sled=*p; *p=pt;
}
else
{
/* ,
*/
k=*p;
while (k!=NULL && strcmp(pt->id,k->id)>=0)
{ j=k; k=k->sled;
}
/* - *pt *j */
j->sled=pt; pt->sled=k;
}
}
/*----------------------------------------------------------*/
/*

*/
/*----------------------------------------------------------*/
void PechSp ( struct EL_SP *p )
/* . : p - */
{ struct EL_SP *i; /* */
printf ("\n:\n");
for ( i=p; i!=NULL; i=i->sled )
puts (i->id);
}
/*-----------------------------------------------------------*/
/* */
6

/*-----------------------------------------------------------*/
main()
{ struct EL_SP *p; /* */
unsigned n ;
/* */
unsigned i ;
/*
*/
char t_id[MAXDL]; /*
*/
printf ("\n \n n=");
scanf ("%u",&n);
getchar(); /* " " */
p=NULL;
/* */
printf (" ");
printf ("( <Enter> )\n");
for ( i=1; i<=n; i++ )
{ gets (t_id);
Vkl (&p,t_id); /* - */
}
PechSp (p);
/* */
printf ("\n\n \n");
getch();
}

1. ?
2. ?
3. ,
i?
4. *i .
5. 1- ?
6.

15.1

, .
7.

15.1 ?

8. Vkl() p,
PechSp() p?
9. Vkl() p ?
10. Vkl() ?
7

11.

:
void PechSp ( struct EL_SP *p )
{
printf ("\n:\n");
for ( ; p != NULL; p =p -> sled )
puts (p -> id);
}

1. .
2.
.
.
3. 15.1,
,
. ,
.

.
4. .


.
8 .
. () :
1.
) ;
) ;
) ;
8

) k- ;
) , k- ;
) k ;
) ;
) ;
) ;
) ( ,
);
) , ;
) , ;
)

;
) , ;
) .
2.
) k- ;
) ;
) .
3. ,
) ;
) ;
) .
4. A
) ;
) , ;
) k (k > 1);
) , ;
9

) (1,3,5).
. ( )
, ,
, .

10