include stdio include conio include windows include locale struct lett

 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <stdio.h>
#include <conio.h>
#include <windows.h>
#include <locale>
struct letter
{
char chr;
letter *ltr;
};
void add(letter **h, letter **t, char lt)
{
letter *n;
if (!(n = (letter *)calloc(1, sizeof(letter))))
{
puts("error!");
return;
}
if (!*t)
{
*t=n;
*h=n;
}
(*t)->ltr = n;
n->chr = lt;
n->ltr = NULL;
*t = n;
}
void see(letter *h)
{
letter *n = h;
while (n)
{
if (!n)
{
puts("error");
return;
}
printf("%c", n->chr);
n = n->ltr;
}
}
void del(letter **h, letter **t)
{
letter *current, *n, *n2 = *h;
for (n = *h; n->ltr->ltr; n = n->ltr)
{
current = n->ltr;
while (current)
{
if (n -> chr == current -> chr)
{
n2->ltr = current->ltr->ltr;
free(current);
current = n2->ltr;
}
else
{
n2 = current;
current = current->ltr;
}
}
}
}
void main()
{
system("cls");
setlocale(LC_ALL, "rus");
letter *h=NULL, *t=NULL;
char *slovo;
if (!(slovo = (char *)calloc(255, sizeof(char))))
return;
printf("Введите слово: ");
gets(slovo);
for (int i =0; *(slovo + i); i++)
add(&h, &t, *(slovo + i));
see(h);
del(&h, &t);
printf("\n\n");
see(h);
getch();
}