02.04.2012, 12:27. Просмотров 395. Ответов 0
как удалить из списка все идентификаторы, начинающиеся с заданной буквы?
C++ |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
| // prog.cpp: определяет точку входа для консольного приложения.
//
// программа включения идентификатора и печати списка
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define MAXDL 9
struct EL_SP
{
char id [MAXDL];
struct EL_SP *sled;
};
void Vkl ( struct EL_SP **p, char t_id[] )
{
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;
}
j->sled=pt; pt->sled=k;
}
}
void PechSp ( struct EL_SP *p )
{
struct EL_SP *i;
printf ("\nResult:\n");
for ( i=p; i!=NULL; i=i->sled )
puts (i->id);
}
int _tmain(int argc, _TCHAR* argv[])
{
struct EL_SP *p;
unsigned n ;
unsigned i ;
char t_id[MAXDL];
printf ("\nEnter the number of identifiers\nn = ");
scanf ("%u",&n);
getchar();
p=NULL;
printf("Enter identifiers' names \n");
printf("After each name press <Enter>\n");
for ( i=1; i<=n; i++ )
{
gets (t_id);
Vkl (&p,t_id);
}
PechSp (p);
printf ("\To complete press any key \n");
getch();
return 0;
} |
|