#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct tl{
int key;
tl *prev,*next;
} *head=NULL,*x=NULL;
struct tl *push(struct tl *head,struct tl*x){
x->prev=NULL;
x->next=head;
if(head) head->prev=x;
return x;
}
// zwykle wypisanie listy
void list(tl *head){
while(head){
printf("%d ",head->key);
head=head->next;
}
}
// rekurencyjne wypisanie listy
void listr(tl *head){
if(head) {
printf("%d ",head->key);
listr(head->next);
}
}
// wypisanie dlugosci listy
int len(tl *head){
int l=0;
while(head){
l++;
head=head->next;
}
return l;
}
// rekurencyjne wypisanie dlugosci listy
int lenr(tl *head){
if(head==NULL) return 0;
else return lenr(head->next)+1;
}
// przeszukiwanie listy
tl *search(tl *head,int k){
while((head!=NULL)&&(head->key!=k))
head=head->next;
return head;
}
// usuniecie elementu listy
tl *eject(tl *head, tl *x){
if(x->next)
if(x->prev){
x->prev->next=x->next;
x->next->prev=x->prev;
}
else{
x->next->prev=NULL;
head=x->next;
}
else
if(x->prev) x->prev->next=NULL;
else head=NULL;
free(x);
return head;
}
// wskazanie na ogon listy
tl *tail(tl *head){
while(head->next)
head=head->next;
return head;
}
// usuniecie ogonu listy
tl *erasetail(tl *head){
tl *x=tail(head);
if(x->prev==NULL) head=NULL;
else x->prev->next=NULL;
free(x);
return head;
}
int m=head->key;
head=head->next;
while(head){
if(head->key->m)m=head->key
head=head->next;
}
return m;
// usuniecie listy
void eraselist(tl *head){
while(head){
tl *x=head;
head=head->next;
free(x);
}
}
int main(void) {
int i=0,n=0;
printf("---LISTY---\n\nliczba elementow listy=");
scanf("%d",&n);
for(i=1;i<=n;i++){
x=(tl*)malloc(sizeof(tl));
x->prev=x->next=NULL;
x->key=i;
head=push(head,x);
}
printf("\n---ZWYKLE WYPISANIE LISTY---\n");
list(head);
printf("\n---REKURENCYJNE WYPISANIE LISTY---\n");
listr(head);
printf("\n---PRZESZUKIWANIE LISTY---\nelement do wyszukania=");
scanf("%d",&i);
x=search(head,i);
if (x)printf("jest=%d",x->key);
else printf("nie ma");
printf("\n---WYPISANIE DLUGOSCI LISTY---\n");
printf("length=%d",len(head));
printf("\n---REKURENCYJNE WYPISANIE DLUGOSCI LISTY---\n");
printf("length=%d",lenr(head));
printf("\n---USUNIECIE ELEMENTU LISTY---\nelement do usuniecia=");
scanf("%d",&i);
x=search(head,i);
if(x) head=eject(head,x);
list(head);
printf("\n---WSKAZANIE NA OGON LISTY---\n");
x=tail(head);
printf("tail=%d",x->key);
printf("\n---USUNIECIE OGONU LISTY---\n");
erasetail(head);
list(head);
printf("\n---WYPISANIE WARTOSCI MAKSYMALNEJ LISTY---\n");
max(head);
printf("\n---USUNIECIE LISTY--- uszkodzone\n");
eraselist(head);
list(head);
getche();
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"}