SHARE
TWEET

Untitled

a guest Apr 18th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include <locale.h>
  5. typedef struct STACK
  6. {
  7.     int temp;
  8.     struct STACK *next;
  9. }stack;
  10. void insert(stack **ptr, int elem)
  11. {
  12.     stack *x = (stack *)malloc(sizeof(stack));
  13.     x->temp = elem;
  14.     x->next = *ptr;
  15.     *ptr = x;
  16. }
  17. int del(stack **ptr, int *error)
  18. {
  19.     stack *old_elem = *ptr;
  20.     int old_temp = 0;
  21.     if (*ptr)
  22.     {
  23.         old_temp = old_elem->temp;
  24.         *ptr = (*ptr)->next;
  25.         free(old_elem);
  26.         *error = 0;
  27.     }
  28.     else
  29.         *error = 1;
  30.     return (old_temp);
  31. }
  32. int main()
  33. {
  34.     int error;
  35.     stack *s1 = NULL;
  36.     int value;
  37.     for (int i = 0; i < 5; i++)
  38.     {
  39.         value = rand() % 10;
  40.         insert(&s1, value);
  41.         printf("%d\n", del(&s1, &error));
  42.     }
  43.     _getch();
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top