Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. //3. Se citesc de la tastatura tastatura N numere intregi.Sa se verifice folosind DOAR stive daca numerele respective
  2. //sunt palindroame, iar numere care sunt palindroame vor fi introduce intr - o stiva.La sfarsit se va afisa continutul stivei
  3. //respective.Cerinta de implementare : Se va implementa o singura metoda de Push/Pop/Peek , se va stii pe care
  4. //stiva se lucreaza transmitand parametrii prin referinta.
  5. #define _CRT_SECURE_NO_WARNINGS
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #define MAX_LENGTH 100
  9.  
  10. int isEmpty(int* stack, int* top)
  11. {
  12.  
  13. if (top == -1)
  14. return 1;
  15. else
  16. return 0;
  17. }
  18.  
  19. int isFull(int* stack, int* top)
  20. {
  21. if (top == MAX_LENGTH - 1)
  22. return 1;
  23. else
  24. return 0;
  25.  
  26. }
  27.  
  28. int Push(int val, int* stack, int* top)
  29. {
  30. if ((*top) == MAX_LENGTH - 1)
  31. printf("stack overflow \n");
  32. else
  33. {
  34. ++(*top);
  35. *(stack + *top) = val;
  36. }
  37.  
  38. }
  39.  
  40.  
  41. int Palindrom(int n)
  42. {
  43. int aux;
  44. int invers = 0;
  45. aux = n;
  46. while (aux)
  47. {
  48. invers = invers * 10 + aux % 10;
  49. aux = aux / 10;
  50. }
  51. if (invers == n)
  52. return 1;
  53. else
  54. return 0;
  55. }
  56.  
  57. int main()
  58. {
  59. int val, stack,top;
  60. int n, invers = 0, aux;
  61. stack = (int*)malloc(MAX_LENGTH *sizeof(int));
  62. top = (int*)malloc(sizeof(int));
  63. top = -1;
  64. printf(" Introduceti numarul n de la tastatura: \n");
  65. scanf("%d", &n);
  66.  
  67. if (Palindrom(n))
  68. push(val, stack, top);
  69. else
  70. printf("Nu este palindrom \n");
  71. system("pause");
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement