fork(1) 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. return 1;
  38. }
  39. void init(struct stos* k)
  40. {
  41. k->sp=0;
  42. memset(k->tab,0,N*sizeof(struct complex));
  43. }
  44.  
  45. int isEmpty(struct stos* k)
  46. {
  47. if (k->sp==0) return 1;
  48. else return 0;
  49. }
  50.  
  51. int isFull(struct stos* k)
  52. {
  53. if (k->sp>=N) return 1;
  54. else return 0;
  55. }
  56.  
  57. void push(struct complex x, struct stos* k)
  58. {
  59. if (isFull(k)) printf ("Stos jest pelny\n");
  60. else {
  61. // k->tab[k->sp].im = x.im;
  62. // k->tab[k->sp].re = x.re;
  63. k->tab[k->sp]=x;
  64. k->sp++;
  65. }
  66. }
  67.  
  68. struct complex* pop(struct stos* k)
  69. {
  70. struct complex* x = (struct complex*)malloc(sizeof(struct complex));
  71. if (isEmpty(k)) {
  72. printf ("Stos jest pusty\n");
  73. return NULL;}
  74. else{
  75. x->im = k->tab[k->sp].im;
  76. x->re = k->tab[k->sp].re;
  77. k->sp--;
  78. }
  79. printf ("%i, %i", x->re,x->im);
  80. return x;
  81. }
Runtime error #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