Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct base
  5. {
  6.     char znak;
  7.     struct base *next;
  8. };
  9.  
  10. struct base *add_stack(struct base *stos, char znak)
  11. {
  12.     struct base *nowy = (struct base*)
  13.         malloc(sizeof(struct base));
  14.  
  15.     if(nowy!=NULL)
  16.     {
  17.         nowy->znak = znak;
  18.         nowy->next = stos;
  19.         stos = nowy;
  20.     }
  21.     return stos;
  22. }
  23.  
  24. void delete_stack(struct base **stos)
  25. {
  26.     struct base *tmp;
  27.     while(*stos)
  28.     {
  29.         tmp = (*stos)->next;
  30.         printf("%c\t", (*stos)->znak);
  31.         free(*stos);
  32.         (*stos) = tmp;
  33.     }
  34. }
  35.  
  36. int main()
  37. {
  38.     char znak;
  39.     struct base *stos = NULL;
  40.     int i = 0;
  41.     for(i; i < 5; i++)
  42.     {
  43.         printf("Podaj znak: ");
  44.         scanf("%c", &znak);
  45.         while(getchar()!='\n');
  46.         stos = add_stack(stos, znak);
  47.     }
  48.     delete_stack(&stos);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement