(temp->prev ) -> next=temp ->next;
(temp->next)-> prev=temp->prev;
#include<alloc.h>
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#define taille 50
typedef struct samourai {
int id;
char nom[taille];
char prenom[50];
int age;
char numero [10];
struct samourai *prev ;
struct samourai *next;
} SAMOURAI ;
SAMOURAI* init(SAMOURAI*);
void affiche (SAMOURAI*);
void recherche_nom(SAMOURAI*,char);
void recherche_id(samourai*,int);
SAMOURAI* erase (SAMOURAI*,int);
SAMOURAI* init (SAMOURAI *prem) {
SAMOURAI *f, *temp;
//f== malloc(sizeof(SAMOURAI));
f=(SAMOURAI*)malloc(sizeof(SAMOURAI));
if (f!=NULL)
{
printf ("-> sozdat nomer samourai \n");
scanf("%i",&(f->id));
printf("-> vashe imia ?\n");
scanf("%s",f->nom);
printf("-> vash vozrast\n");
scanf("%i",&(f->age));
printf("-> vash nomer telefona\n");
scanf("%s",f->numero);
if (prem!=NULL)
{
temp=prem;
while (temp->next!=NULL) {
temp=temp->next;
}
temp->next=f;
f->prev=temp;
f->next=NULL;
}
else {
f->prev=NULL;
f->next=NULL;
}
return f;
}
else return NULL;
}
void recherche_id(samourai *prem,int k) //sdes nujen
{
SAMOURAI *temp;
temp=prem;
//while (temp!= NULL)
if (temp->id==k)
{ affiche(temp);
//printf("%i\n",prem);
}
}
void affiche (SAMOURAI* f)
{
printf("%i %s %i %s \n",f->id,f->nom,f->age,f->numero);
}
void recherche_nom (samourai *prem, char n)
{
SAMOURAI *temp;
temp=prem;
while (temp!=NULL)
{
if (temp->nom[0]==n){
affiche(temp);
}
temp=temp->next;
}
}
SAMOURAI* erase (SAMOURAI *prem, int id)
{
SAMOURAI *temp,*newfirst;
temp=prem;
int found=0;
while (temp!=NULL && found==0)
{
if ( temp->id==id) found =1;
else temp=temp->next;
}
if (temp!=NULL) {
if (temp==prem) {
prem=prem->next;
if (prem!=NULL) prem->prev=NULL;
}
else {
(temp->prev ) -> next=temp ->next;
(temp->next)-> prev=temp->prev;
}
free(temp);
}
return prem;
}
int main()
{
SAMOURAI *prem,*temp;
prem=NULL;
temp=NULL;
int choix=0,supp=-1,k;
char c;
do {
printf("menu\n");
printf("0 vihod .\n");
printf("1 dobavlenie dannih familiy .\n");
printf("2 udalit' samourai sootvetstvuyshiy vvedennomu nomeru .\n");
printf("3 naity familiy po bukve.\n");
printf("4 pokazat vse soderjimoe.\n");
printf("5 nahojdenie nujnogo samourai po nomeru \n");
scanf("%d",&choix);
switch(choix) {
case 1: if(prem==NULL) prem=init(NULL);
else init(prem);
break;
case 2: printf("numero samourai ? \n");
scanf("%d",&supp);
prem=erase (prem,supp);
if (k==0) printf("net takogo samourai.\n");
else printf(" oshibka vvoda ????? .\n");
break;
case 3: printf("Lettre.\n");
getchar();
scanf("%c",&c);
recherche_nom(prem,c);
break;
case 4 : temp=prem ;
while (temp!=NULL)
{ affiche(temp);
temp=temp->next;
} break;
case 5 : printf("nomer samourai\n");
//getchar ();
scanf("%d",&k );
recherche_id(prem,k);
break;
default: break;
}
} while (choix!=0);
}