#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <stddef.h>
struct wezel
{
char imie[20];
int wiek;
struct wezel *nastepny;
struct wezel *poprzedni;
};
struct wezel *dodaj(struct wezel *ogon )
{
struct wezel *nowy;
nowy = (struct wezel*)malloc(sizeof(struct wezel));
ogon->nastepny = nowy;
nowy->poprzedni=ogon;
nowy->nastepny = NULL;
return(nowy);
}
struct wezel *usun( struct wezel *glowa )
{
struct wezel *temp;
struct wezel *przed_ogon;
temp = glowa;
if(temp->nastepny == NULL)
{
free(temp);
return NULL;
}
while( temp->nastepny->nastepny !=NULL )
{
temp = temp->nastepny;
}
przed_ogon = temp;
free(przed_ogon->nastepny);
przed_ogon->nastepny=NULL;
return przed_ogon;
}
void wyswietl(struct wezel *glowa)
{
struct wezel *temp;
temp = glowa;
while(temp!=NULL)
{
printf("%s %d\n",temp->imie,temp->wiek);
temp=temp->nastepny;
}
}
void wyswietl_aktualny(struct wezel *aktualny)
{
printf("Aktualny element:\n\n");
printf("%s %d\n\n",aktualny->imie,aktualny->wiek);
}
int main(int argc, char *argv[])
{
char k;
struct wezel *glowa;
struct wezel *ogon;
struct wezel *aktualny;
glowa = (struct wezel*)malloc(sizeof(struct wezel));
glowa->nastepny=NULL;
glowa->poprzedni=NULL;
printf("Podaj imie i wiek pierwszej osoby:\n");
scanf("%s%d",&glowa->imie,&glowa->wiek);
ogon=glowa;
printf("Czy dodac nastepny element: y/n\n");
k=getch();
while(k=='y')
{
ogon = dodaj(ogon);
printf("Podaj imie i wiek nastepnej osoby:\n");
scanf("%s%d",&ogon->imie,&ogon->wiek);
printf("Czy dodac nastepny element: y/n\n");
k=getch();
}
printf("\nElementy listy wypisane od poczatku do konca:\n");
wyswietl(glowa);
printf("\nprzegladanie listy po jednym elemencie:\n\n");
aktualny = glowa;
wyswietl_aktualny(aktualny);
k=NULL;
do
{
if(k=='n')
{
if(aktualny->nastepny==NULL)
{
printf("Brak nastepnego elementu\n\n");
wyswietl_aktualny(aktualny);
}
else
{
aktualny = aktualny->nastepny;
wyswietl_aktualny(aktualny);
}
}
if(k=='p')
{
if(aktualny->poprzedni==NULL)
{
printf("Brak nastepnego elementu\n\n");
wyswietl_aktualny(aktualny);
}
else
{
aktualny = aktualny->poprzedni;
wyswietl_aktualny(aktualny);
}
}
printf("Wybierz co dalej: \n n-nastepny element \n p-poprzedni element \n u-usun biezacy element \n d-dodaj nowy za tym elementem \n z-zakoncz\n\n");
k=getch();
}
while(k!='z');
system("Pause");
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"}