#include <stdio.h>
#include <stdlib.h>
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;
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}