Advertisement
Guest User

Dżejzi

a guest
Jan 19th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.52 KB | None | 0 0
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string.h>
  6. #include<conio.h>
  7.  
  8. void ubranko();
  9. void usuwanie();
  10.  
  11. int licznik=1;
  12.  
  13.  
  14. struct Ubranie{
  15.  
  16. int ID;
  17. char nazwa[20];
  18. char r_u[20];
  19. int cena;
  20. char i_wyp[20];
  21. char n_wyp[20];
  22. char data[10];
  23. int kaucja;
  24. char kom[30];
  25.  
  26.  
  27.  
  28. };
  29.  
  30.  
  31. struct lista{
  32.  
  33. Ubranie dane;
  34. struct lista *next;
  35. struct lista *prev;
  36.  
  37. };
  38.  
  39.  
  40. struct lista *head=NULL;
  41. struct lista *tail=NULL;
  42. struct lista *element=NULL;
  43. struct lista *tmp=NULL;
  44.  
  45. main()
  46. {
  47.  
  48.  
  49.  
  50. ubranko(); // to dodaj do pierwszego case
  51. usuwanie();
  52.  
  53.  
  54.  
  55.  
  56.  
  57. }
  58.  
  59.  
  60. void  ubranko()
  61. {
  62.     if(head==NULL)
  63.     {
  64.         head = new lista;
  65.         head->dane.ID=1;
  66.         fflush(stdin);
  67.         printf("Nazwa Ubrania: ");
  68.         scanf("%[-' A-Z,a-z]", head->dane.nazwa);
  69.         fflush(stdin);
  70.         printf("\nRodzaj ubrania: ");
  71.         scanf("%[-' A-Z,a-z]", head->dane.r_u);
  72.         fflush(stdin);
  73.         printf("\nCena wypozyczenia: ");
  74.         scanf("%d", head->dane.cena);
  75.         fflush(stdin);
  76.         printf("\nImie wypozyczajacego: ");
  77.         scanf("%[-' A-Z,a-z]", head->dane.i_wyp);
  78.         fflush(stdin);
  79.         printf("\nNazwisko wypozyczajacego: ");
  80.         scanf("%[-' A-Z,a-z]", head->dane.n_wyp);
  81.         fflush(stdin);
  82.         printf("\nData: ");
  83.         scanf("%[-. 0-9]", head->dane.data);
  84.         fflush(stdin);
  85.         printf("\nKaucja: ");
  86.         scanf("%d", head->dane.kaucja);
  87.         fflush(stdin);
  88.         printf("\nKomentarz: ");
  89.         scanf("%[-' A-Z,a-z]", head->dane.kom);
  90.         head->next=NULL;
  91.         head->prev=NULL;
  92.         tail=head;
  93.  
  94.  
  95.     }
  96.     else
  97.     {
  98.  
  99.         element= new lista;
  100.         element->prev=tail;
  101.         tail->next=element;
  102.         element->next=NULL;
  103.         element->dane.ID=licznik+1;
  104.         licznik++;
  105.         fflush(stdin);
  106.         printf("Nazwa Ubrania: ");
  107.         scanf("%[-' A-Z,a-z]", head->dane.nazwa);
  108.         fflush(stdin);
  109.         printf("\nRodzaj ubrania: ");
  110.         scanf("%[-' A-Z,a-z]", head->dane.r_u);
  111.         fflush(stdin);
  112.         printf("\nCena wypozyczenia: ");
  113.         scanf("%d", head->dane.cena);
  114.         fflush(stdin);
  115.         printf("\nImie wypozyczajacego: ");
  116.         scanf("%[-' A-Z,a-z]", head->dane.i_wyp);
  117.         fflush(stdin);
  118.         printf("\nNazwisko wypozyczajacego: ");
  119.         scanf("%[-' A-Z,a-z]", head->dane.n_wyp);
  120.         fflush(stdin);
  121.         printf("\nData: ");
  122.         scanf("%[-. 0-9]", head->dane.data);
  123.         fflush(stdin);
  124.         printf("\nKaucja: ");
  125.         scanf("%d", head->dane.kaucja);
  126.         fflush(stdin);
  127.         printf("\nKomentarz: ");
  128.         scanf("%[-' A-Z,a-z]", head->dane.kom);
  129.         tail=element;
  130.         element=NULL;
  131.  
  132.     }
  133.  
  134.  
  135. }
  136. void usuwanie()
  137. {
  138.     int AJDI;
  139.     printf("Podaj ID: ");
  140.     fflush(stdin);
  141.     while(scanf("%d", &AJDI)!=1||(AJDI<head->dane.ID||AJDI>tail->dane.ID))
  142.     {
  143.         fflush(stdin);
  144.         printf("Wpisz ponownie\n");
  145.         fflush(stdin);
  146.     }
  147. if(head==NULL)
  148. {
  149.  
  150.  printf("\n");
  151.  printf("Nie ma zadnego elementu do usuniecia\n");
  152.  printf("\n");
  153.  
  154.  
  155. }
  156. else if(AJDI > licznik)
  157. {
  158.      printf("Taki element nie istnieje\n");
  159.      printf("\n");
  160. }
  161. else
  162. {
  163.     tmp=head;
  164.     for(int i=1; i<=licznik; i++)
  165.     {
  166.          if(tmp->dane.ID==AJDI)
  167.          {
  168.             if(tmp->prev==tmp->next)
  169.                 {
  170.                     head=NULL;
  171.                     tail=NULL;
  172.                     free (tmp);
  173.                     return;
  174.                 }
  175.             else if(tmp->prev==NULL)
  176.                 {
  177.                    head=tmp->next;
  178.                    head->prev=NULL;
  179.                    free(tmp);
  180.                    licznik--;
  181.                    element=head;
  182.                    break;
  183.                 }
  184.  
  185.             else if(tmp->prev!=NULL&&tmp->next!=NULL)
  186.                 {
  187.                     element=tmp->prev;
  188.                     element->next=tmp->next;
  189.                     element=tmp->next;
  190.                     element->prev=tmp->prev;
  191.                     free(tmp);
  192.                     licznik--;
  193.                     break;
  194.  
  195.                 }
  196.  
  197.             else if(tmp->next==NULL)
  198.             {
  199.              tail=tmp->prev;
  200.              tail->next=NULL;
  201.              free (tmp);
  202.              licznik--;
  203.              return;
  204.  
  205.             }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.         }
  212.         else
  213.         {
  214.             tmp=tmp->next;
  215.         }
  216.   }
  217.  
  218.   for(;AJDI<=licznik;AJDI++)
  219.   {
  220.       element->dane.ID-=1;
  221.       element=element->next;
  222.   }
  223.  
  224. }
  225.  
  226.  
  227.  
  228. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement