Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<algorithm>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- #include<conio.h>
- void ubranko();
- void usuwanie();
- int licznik=1;
- struct Ubranie{
- int ID;
- char nazwa[20];
- char r_u[20];
- int cena;
- char i_wyp[20];
- char n_wyp[20];
- char data[10];
- int kaucja;
- char kom[30];
- };
- struct lista{
- Ubranie dane;
- struct lista *next;
- struct lista *prev;
- };
- struct lista *head=NULL;
- struct lista *tail=NULL;
- struct lista *element=NULL;
- struct lista *tmp=NULL;
- main()
- {
- ubranko(); // to dodaj do pierwszego case
- usuwanie();
- }
- void ubranko()
- {
- if(head==NULL)
- {
- head = new lista;
- head->dane.ID=1;
- fflush(stdin);
- printf("Nazwa Ubrania: ");
- scanf("%[-' A-Z,a-z]", head->dane.nazwa);
- fflush(stdin);
- printf("\nRodzaj ubrania: ");
- scanf("%[-' A-Z,a-z]", head->dane.r_u);
- fflush(stdin);
- printf("\nCena wypozyczenia: ");
- scanf("%d", head->dane.cena);
- fflush(stdin);
- printf("\nImie wypozyczajacego: ");
- scanf("%[-' A-Z,a-z]", head->dane.i_wyp);
- fflush(stdin);
- printf("\nNazwisko wypozyczajacego: ");
- scanf("%[-' A-Z,a-z]", head->dane.n_wyp);
- fflush(stdin);
- printf("\nData: ");
- scanf("%[-. 0-9]", head->dane.data);
- fflush(stdin);
- printf("\nKaucja: ");
- scanf("%d", head->dane.kaucja);
- fflush(stdin);
- printf("\nKomentarz: ");
- scanf("%[-' A-Z,a-z]", head->dane.kom);
- head->next=NULL;
- head->prev=NULL;
- tail=head;
- }
- else
- {
- element= new lista;
- element->prev=tail;
- tail->next=element;
- element->next=NULL;
- element->dane.ID=licznik+1;
- licznik++;
- fflush(stdin);
- printf("Nazwa Ubrania: ");
- scanf("%[-' A-Z,a-z]", head->dane.nazwa);
- fflush(stdin);
- printf("\nRodzaj ubrania: ");
- scanf("%[-' A-Z,a-z]", head->dane.r_u);
- fflush(stdin);
- printf("\nCena wypozyczenia: ");
- scanf("%d", head->dane.cena);
- fflush(stdin);
- printf("\nImie wypozyczajacego: ");
- scanf("%[-' A-Z,a-z]", head->dane.i_wyp);
- fflush(stdin);
- printf("\nNazwisko wypozyczajacego: ");
- scanf("%[-' A-Z,a-z]", head->dane.n_wyp);
- fflush(stdin);
- printf("\nData: ");
- scanf("%[-. 0-9]", head->dane.data);
- fflush(stdin);
- printf("\nKaucja: ");
- scanf("%d", head->dane.kaucja);
- fflush(stdin);
- printf("\nKomentarz: ");
- scanf("%[-' A-Z,a-z]", head->dane.kom);
- tail=element;
- element=NULL;
- }
- }
- void usuwanie()
- {
- int AJDI;
- printf("Podaj ID: ");
- fflush(stdin);
- while(scanf("%d", &AJDI)!=1||(AJDI<head->dane.ID||AJDI>tail->dane.ID))
- {
- fflush(stdin);
- printf("Wpisz ponownie\n");
- fflush(stdin);
- }
- if(head==NULL)
- {
- printf("\n");
- printf("Nie ma zadnego elementu do usuniecia\n");
- printf("\n");
- }
- else if(AJDI > licznik)
- {
- printf("Taki element nie istnieje\n");
- printf("\n");
- }
- else
- {
- tmp=head;
- for(int i=1; i<=licznik; i++)
- {
- if(tmp->dane.ID==AJDI)
- {
- if(tmp->prev==tmp->next)
- {
- head=NULL;
- tail=NULL;
- free (tmp);
- return;
- }
- else if(tmp->prev==NULL)
- {
- head=tmp->next;
- head->prev=NULL;
- free(tmp);
- licznik--;
- element=head;
- break;
- }
- else if(tmp->prev!=NULL&&tmp->next!=NULL)
- {
- element=tmp->prev;
- element->next=tmp->next;
- element=tmp->next;
- element->prev=tmp->prev;
- free(tmp);
- licznik--;
- break;
- }
- else if(tmp->next==NULL)
- {
- tail=tmp->prev;
- tail->next=NULL;
- free (tmp);
- licznik--;
- return;
- }
- }
- else
- {
- tmp=tmp->next;
- }
- }
- for(;AJDI<=licznik;AJDI++)
- {
- element->dane.ID-=1;
- element=element->next;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement