SHARE
TWEET

Stack_array

a guest Nov 23rd, 2010 173 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //by FamiHug
  2. #include <stdio.h>
  3. #define MAX 50
  4. float a[MAX];
  5. int t;
  6.  
  7. void init_stack();
  8. int full();
  9. int empty();
  10. void push(float);
  11. float pop();
  12.  
  13. int main()
  14. {
  15.         float y;
  16.         init_stack();
  17.         printf("CHUONG TRINH MINH HOA STACK\n");
  18.         printf("Da khoi tao stack. T=%d\n",t);
  19.         printf("Them vao stack 1 phan tu: ");
  20.         scanf("%f",&y);
  21.         push(y);
  22.         printf("T=%d\n",t);
  23.         printf("Them vao stack 1 phan tu nua: ");
  24.         scanf("%f",&y);
  25.         push(y);
  26.         printf("T=%d\n",t);
  27.         printf("Lay 1 phan tu ra khoi stack.\n");
  28.         y = pop();
  29.         printf("T=%d x=%g\n",t,y);
  30.         return 1;
  31. }
  32.  
  33. void init_stack()
  34. {
  35.         t=0;
  36. }
  37.  
  38. int full()
  39. {
  40.         if(t==MAX) return 1;
  41.         else return 0;
  42. }
  43.  
  44. int empty()
  45. {
  46.         if(t==0) return 1;
  47.         else return 0;
  48. }
  49.  
  50. void push(float x)
  51. {
  52.         if(full()) printf("\nStack day!");
  53.         else
  54.         {
  55.                 a[t] = x;
  56.                 t++;
  57.         }
  58. }
  59.  
  60. float pop()
  61. {
  62.         if(empty())
  63.         {
  64.                 printf("\nStack rong!");
  65.                 return 0;
  66.         }
  67.         else
  68.         {
  69.                 t--;
  70.                 return a[t];
  71.         }
  72. }
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