nujno na C
Цитата:
#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 recherche_id(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));
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;}
SAMOURAI* erase (SAMOURAI *prem, int id)
{
SAMOURAI *temp,*newfirst;
temp=prem;
int found=0;
while (temp!=NULL && !found) {
if ( temp->id==id) found = 1;
else temp=temp->next;
}
if (found) {
if (temp==prem) {
prem=prem->next;
if (prem!=NULL) {
prem->prev=NULL;
} else {
prem = NULL;
}
} else {
(temp->prev )->next=temp ->next;
if (temp->next != NULL) {
(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("2 chtobi udalit vvedenniy nomer samourai \n");
scanf("%d",&choix);
switch(choix) {
case 2: printf("nomer samourai ? \n");
scanf("%d",&supp);
prem=erase (prem,supp);
if (supp==id) printf("net takogo nomera samourai.\n");// stavim vmesto id=0 , rabotaet no ne correctno
else
printf(" samourai udalen .\n");
break;
default: break;
} while (choix!=0);
}
icq 490015486 mojet kto pomojet razobratsia