#include <stdio.h>
#include <stdlib.h>
typedef struct Element{
int key;
struct Element *next;
}ListaJ;
ListaJ *wstawG(ListaJ *h,int k){
ListaJ *nowa=(ListaJ*)malloc(sizeof(ListaJ));
nowa->key=k;
// nowa->next=NULL;
nowa->next=h;
h=nowa;
return h;
}
ListaJ *wstawO(ListaJ *h, int k){
ListaJ *nowa=(ListaJ*)malloc(sizeof(ListaJ));
nowa->key=k;
nowa->next=NULL;
if(h==NULL){
h=nowa;
} else{
ListaJ *walker;
walker=h;
while(walker->next!=NULL)
walker=walker->next;
walker->next=nowa;
}
return h;
}
void pokaz(ListaJ *h){
if(h!=NULL){
ListaJ* walker=h;
while (walker!=NULL){
printf("%d,",walker->key);
walker=walker->next;
}
} else{
printf("lista pusta");
}
}
int szukaj(ListaJ *h,int k){
ListaJ *walker=h;
while ((walker!=NULL) && (walker->key!=k)){
walker=walker->next;
}
return walker;
}
ListaJ *usunG(ListaJ *h){
ListaJ *tmp=h;
if(tmp!=NULL){
h=h->next;
free(tmp);
tmp=NULL;
}
return h;
}
ListaJ *usunO(ListaJ *h){
ListaJ *tmp=h;
if(tmp){
ListaJ *walker=h;
while (walker->next!=NULL){
tmp=walker;
walker=walker->next;
}
if(walker==tmp){
free(h);
h=NULL;
} else{
free(walker);
tmp->next=NULL;
walker=NULL;
}
}
return h;
}
int main() {
ListaJ *head=NULL;
head=wstawO(head,8);
head=wstawO(head,4);
head=wstawG(head,5);
head=wstawG(head,1);
pokaz(head);
ListaJ* p=szukaj(head,9);
if(p) printf("\nznaleziono");
else printf("\nnieznaleziono\n");
head=usunG(head);
pokaz(head);
printf("\n");
head=usunO(head);
pokaz(head);
return 0;
}
{"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"}