fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define N 20
  5.  
  6. struct complex {
  7. int re;
  8. int im;
  9. };
  10.  
  11. struct stos {
  12. int sp;
  13. struct complex tab[N];
  14. };
  15.  
  16. void init(struct stos*);
  17. int isEmpty(struct stos*);
  18. int isFull(struct stos*);
  19. struct complex* pop(struct stos* k);
  20. void push(struct complex x, struct stos* k);
  21.  
  22.  
  23. int main()
  24. {
  25. struct stos l;
  26. struct complex bb;
  27. int i;
  28. init (&l);
  29. bb.re=2;
  30. bb.im=1;
  31. push(bb,&l);
  32. for (i=0;i<N;i++)
  33. {
  34. printf("%i +j%i\n",l.tab[i].re,l.tab[i].im);
  35. }
  36. pop(&l);
  37. bb.re = 3;
  38. push(bb, &l);
  39. printf("\n--\n");
  40. for (i=0;i<N;i++)
  41. {
  42. printf("%i +j%i\n",l.tab[i].re,l.tab[i].im);
  43. }
  44. return 0;
  45. }
  46. void init(struct stos* k)
  47. {
  48. k->sp=0;
  49. memset(k->tab,0,N*sizeof(struct complex));
  50. }
  51.  
  52. int isEmpty(struct stos* k)
  53. {
  54. if (k->sp==0) return 1;
  55. else return 0;
  56. }
  57.  
  58. int isFull(struct stos* k)
  59. {
  60. if (k->sp>=N) return 1;
  61. else return 0;
  62. }
  63.  
  64. void push(struct complex x, struct stos* k)
  65. {
  66. if (isFull(k)) printf ("Stos jest pelny\n");
  67. else {
  68. // k->tab[k->sp].im = x.im;
  69. // k->tab[k->sp].re = x.re;
  70. k->tab[k->sp]=x;
  71. k->sp++;
  72. }
  73. }
  74.  
  75. struct complex* pop(struct stos* k)
  76. {
  77. struct complex* x = (struct complex*)malloc(sizeof(struct complex));
  78. if (isEmpty(k)) {
  79. printf ("Stos jest pusty\n");
  80. return NULL;}
  81. else{
  82. x->im = k->tab[k->sp].im;
  83. x->re = k->tab[k->sp].re;
  84. k->sp--;
  85. }
  86. printf ("%i, %i", x->re,x->im);
  87. return x;
  88. }
Success #stdin #stdout 0s 2140KB
stdin
Standard input is empty
stdout
2 +j1
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0, 0
--
3 +j1
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0
0 +j0