Advertisement
dzieciol

LIFO

Apr 13th, 2016
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct stos{
  5. int element;
  6. struct stos *wskaznik;
  7.  
  8. };
  9. struct stos *nowy, *stary;
  10.  
  11. void push(int n){
  12.  
  13.     stary = nowy;
  14.     nowy = malloc(sizeof (struct stos));
  15.     nowy->element = n;
  16.     nowy -> wskaznik = stary;
  17.  
  18. }
  19. void pop (void){
  20.  
  21.     if(nowy -> element != NULL){
  22.         stary = nowy -> wskaznik;
  23.         printf ("usunales %d \n\n\n\n",nowy ->element);
  24.         free(nowy -> wskaznik);
  25.         nowy = stary;
  26.     }
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32.  
  33. int n;
  34. int k;
  35. while (k!= 4){
  36.     printf("kolejka LIFO");
  37.     printf("\n \n \t \t \t =====CO CHCESZ ZROBIC?=====");
  38.     printf("\n \n \t 1. Wydrukuj oststni element");
  39.     printf("\n\n\t 2. Dodaj element");
  40.     printf ("\n\n\t 3. Zdejmij ostatni element");
  41.     printf ("\n\n\t 4. Zakoncz program\n\n");
  42.  
  43.     scanf ("%d",&k);
  44.         switch(k){
  45.     case 1 :
  46.         {
  47.         printf("%d",nowy->element);
  48.         }break;
  49.     case 2:
  50.         {
  51.         printf("jaka liczbe chcesz dodac?");
  52.         scanf ("%d",&n);
  53.         push(n);
  54.         printf ("pomyslnie dodano %d na stosn\n\n\n\n",n);
  55.         }break;
  56.     case 3:
  57.         {
  58.         pop();
  59.  
  60.         }break;
  61.  
  62.  
  63.  
  64. };}
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement