Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- //listy dwukierunkowe//
- struct Dane{
- char tytul[50];
- char autor[100];
- int rok;
- };
- struct ksiazka{
- struct Dane dane;
- struct ksiazka*pop;
- struct ksiazka*nast;
- };
- typedef struct ksiazka KS;
- typedef KS*WSK;
- void dodaj(struct Dane d, WSK*pocz){
- WSK nowy, ost;
- nowy=(WSK)malloc(sizeof(KS));
- nowy->dane.rok=d.rok;
- strcpy(nowy->dane.tytul,d.tytul);
- strcpy(nowy->dane.autor,d.autor);
- if(*pocz==NULL){
- (*pocz)=nowy;
- nowy->pop=NULL;
- nowy->nast=NULL;
- return;
- }
- ost=(*pocz);
- while(ost->nast!=NULL);
- ost=ost->nast;
- ost->nast=nowy;
- nowy->nast=NULL;
- nowy->pop=ost;
- }
- void wypisz(WSK pocz){
- WSK pom=pocz;
- int i=1;
- while(pom!=NULL){
- printf("%d.%s %s %d ", i++,pom->dane.tytul,pom->dane.autor,pom->dane.rok);
- pom=pom->nast;
- }
- }
- void czysc(WSK*pocz){
- WSK pom;
- if((*pocz)!=NULL)
- while((*pocz)->nast!=NULL)
- (*pocz)=(*pocz)*nast;
- free((*pocz)->pop);
- }
- free(*pocz);
- int main()
- {
- WSK pocz=NULL;
- FILE*f;
- f=fopen("...", "rt");
- if(f==NULL)...
- while(fscanf(f,"%s\n%s\n%d", d.tytul,d.autor,&(d.rok))==3){
- return 0;
- }
- dodaj(d,&pocz);
- }
- fclose(f);
- wypisz(pocz);
- printf("Podaj ksiazke, ktora chcesz znalezc");
- printf("Tytul: ");
- scanf("%s", d.tytul.);
- printf("Autor: ");
- scanf("%s", d.autor);
- printf("Rok: ", d.rok);
- scanf("%s", &(d.rok));
- if(czIstnieje(d, pocz))==1
- printf("Istnieje");
- else
- printf("Brak");
- czysc(&pocz);
- return 0;
- }
- int czyIstnieje(struct Dane d, WSK pocz){
- while(pocz!=NULL){
- if(strcmp(d.tytul, pocz->dane.tytul)
- strcmp(d.autor, pocz->dane.autor)&&d.rok==pocz->dane.rok)
- return 1;
- }
- pocz=pocz->nast;
- }
- }
Add Comment
Please, Sign In to add comment