#include #include struct element{ int k; struct element *prev; struct element *next; }; struct element *lista_dodaj(struct element *head, struct element *nowy); void lista_wyswietl(struct element *head); struct element *lista_szukaj(struct element *head,int k); struct element* lista_usun(struct element *head, struct element *do_usu); int main(){ struct element *head = NULL,*nowy=NULL; char z; int liczba; while(1){ printf("\nco chcesz zrobic?"); printf("\nd - dodać"); printf("\ns - szukac"); printf("\nu - usunac"); printf("\no - odwrocic liste"); printf("\nw - wyswietlic"); printf("\nq - wyjsc\n"); fflush(stdin); z = getchar(); switch(z){ case 'd': nowy=(struct element*) malloc (sizeof(struct element)); printf("\npodaj wartosc elelmentu do wstawienia: "); fflush(stdin); scanf("%d",&liczba); nowy->k=liczba; head = lista_dodaj(head,nowy); break; case 'w': lista_wyswietl(head); break; case 's': printf("\npodaj wartosc do znalezienia: "); fflush(stdin); scanf("%d",&liczba); nowy = lista_szukaj(head,liczba); printf("\n%p \n",nowy); break; case 'u': printf("\npodaj wartosc do usuniecia: "); fflush(stdin); scanf("%d",&liczba); nowy = lista_szukaj(head,liczba); if (nowy == NULL){ printf("\n brak elementu do usuniecia"); }else{ head = lista_usun(head,nowy); printf("\n element usnieto"); } break; case 'q': return 0; } } return 0; } 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; } void lista_wyswietl(struct element *head){ struct element *x = head; while(x!=NULL){ printf("%d ",x->k); x=x->next; } } struct element *lista_szukaj(struct element *head,int sz){ struct element *x = head; while((x!=NULL)&&(x->k!=sz)){ x=x->next; } return x; } struct element* lista_usun(struct element *head, struct element *do_usu){ if(do_usu->prev != NULL){ do_usu->prev->next = do_usu->next; } else{ head = do_usu->next; } if(do_usu->next != NULL){ do_usu->next->prev = do_usu->prev; } return head; }