#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();
}