#include #include #include struct element { int k; char tekst[50]; struct element *prev; struct element *next; int id; }; void lista_wyswietl(struct element *head); struct element *lista_dodaj(struct element *head, struct element *nowy); struct element *lista_usun(struct element *head, struct element *nowy); struct element *lista_posz(struct element *head, int klucz); struct element *lista_odwroc(struct element *head); main() { struct element *head=NULL, *nowy=NULL; char z; int liczba, klucz, index=0; while(1) { printf("nco chcesz zrobic?"); printf("nd-dodac"); printf("ns-szukac"); printf("nu-usunac"); printf("no-odwrocic liste"); printf("nw-wyswietlic"); printf("nq-wyjscn"); fflush(stdin); z=getchar(); switch(z) { case 'd': nowy=(struct element*)malloc(sizeof(struct element)); printf("npodaj wartosc elementu do wstawienia: "); scanf("%d",&liczba); nowy->k=liczba; nowy->id=index++; if(nowy->id%2!=0) { printf("nPodaj tekst do wstawienia: "); fflush(stdin); scanf("%s",nowy->tekst); } else strcpy(nowy->tekst," "); head=lista_dodaj(head,nowy); printf("%d",head->id); break; case 'w': lista_wyswietl(head); break; case 'u' : break; case 'o' :head=lista_odwroc(head); break; case 's' :fflush(stdin); printf("nPodaj wartosc klucza jaka chcesz wyszukac"); scanf("%d",&klucz); printf("%d",*lista_posz(head, klucz)); break; case 'q': return 0; } } } void lista_wyswietl(struct element *head) { struct element *x=head; while(x!=NULL) { printf("%d",x->k); printf("%sn",x->tekst); x=x->next; } } struct element *lista_dodaj(struct element *head, struct element *nowy) { nowy->prev=NULL; nowy->next=head; if(head!=NULL) head->prev=nowy; head=nowy; return head; } struct element *lista_usun(struct element *head, struct element *x) { if(x->prev!=NULL) (x->prev)->next=x->next; else head=x->next; if (x->next!=NULL) (x->next)->prev=x->prev; } struct element *lista_posz(struct element *head, int klucz) { struct element *x=NULL; x=head; while(x!=NULL && x->k!=klucz) x=x->next; return x; } struct element *lista_odwroc(struct element *head) { struct element *x=NULL; struct element *temp=NULL; struct element *temp1=NULL; x=head; while(x!=NULL) {temp1=(struct element*)malloc(sizeof(struct element)); temp1->k=x->k; temp=lista_dodaj(temp,temp1); x=x->next; } return temp; }