Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <assert.h>
  4. typedef struct Element{
  5.     int dane;
  6.     struct Element * nast;
  7. }Element;
  8.  
  9. struct Handler{
  10.     Element *beg,*end;
  11. };
  12.  
  13. void push_back(struct Handler *h,int value)
  14. {
  15.     Element * nowy;
  16.     nowy =malloc(sizeof(Element));
  17.     nowy->dane=value;
  18.     nowy->nast=NULL;
  19.  
  20.     if(h->beg==NULL){
  21.         h->beg=nowy;
  22.         h->end=nowy;
  23.     }
  24.     else{
  25.         ((h->end)->nast)=nowy;
  26.         h->end=nowy;
  27.     }
  28. }
  29.  
  30. void push_front(struct Handler *h,int value)
  31. {
  32.     Element *nowy=(Element *)malloc(sizeof(Element));
  33.     assert(nowy!=NULL);
  34.  
  35.     nowy->dane=value;
  36.     if(h->beg!=NULL)
  37.     {
  38.         nowy->nast=h->beg;
  39.         h->beg=nowy;
  40.     }
  41.     else
  42.         nowy->nast=NULL;
  43.         h->beg=nowy;
  44.         h->end=nowy;
  45. }
  46.  
  47. int *find(struct Handler *h,int find_value)
  48. {
  49.     Element *adres=h->beg;
  50.     while(adres!= NULL)
  51.     {
  52.         if(adres->dane==find_value)
  53.             return adres;
  54.         adres=adres->nast;
  55.     }
  56.     return NULL;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. int main()
  63. {
  64.     struct Handler handler;
  65.     handler.beg=NULL;
  66.     handler.end=NULL;
  67.     push_front(&handler,9);
  68.     push_back(&handler,11);
  69.     push_back(&handler,12);
  70.     push_back(&handler,13);
  71.     push_front(&handler,10);
  72.     Element *adres=handler.beg;
  73.  
  74.     while(adres!=NULL)
  75.     {
  76.         printf("%d \n",adres->dane);
  77.         adres=adres->nast;
  78.  
  79.     }
  80.  
  81.     printf("\n \n ");
  82.  
  83.     printf("*%d = %d\n",find(&handler,12),*find(&handler,12));
  84.  
  85.  
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement