Guest User

Untitled

a guest
May 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct str
  5. {
  6. char x;
  7. struct str *nast, *poprz;
  8. };
  9. typedef struct str EL;
  10. typedef EL *WSK;
  11. int palindrom(WSK lista)
  12. {
  13.  
  14. WSK temp1=lista;
  15. WSK temp2=lista;
  16. while(temp2->nast!=NULL)
  17. {
  18. temp2=temp2->nast;
  19. }
  20. while(temp1)
  21. {
  22. if(temp1->x != temp2->x)
  23. return 0;
  24.  
  25. temp1=temp1->nast;
  26. temp2=temp2->poprz;
  27. }
  28. return 1;
  29. }
  30.  
  31. void wstaw(WSK *x, WSK nowy)
  32. {
  33. WSK temp=*x;
  34. nowy->nast=NULL;
  35. if(*x==NULL)
  36. {
  37. *x=nowy;
  38. (*x)->poprz=NULL;
  39. return 0;
  40. }
  41.  
  42. while(temp->nast)
  43. {
  44. temp=temp->nast;
  45. }
  46. temp->nast=nowy;
  47. nowy->poprz=temp;
  48. return 0;
  49. }
  50.  
  51. int main()
  52. {
  53. WSK lista=NULL;
  54.  
  55. WSK nowy=(WSK)malloc(sizeof(EL));
  56. while(scanf("%c",&(nowy->x)))
  57. {
  58. if(nowy->x == '\n') break;
  59. wstaw(&lista,nowy);
  60. nowy=(WSK)malloc(sizeof(EL));
  61. }
  62. WSK temp=lista;
  63. while(lista)
  64. {
  65. printf("%c",lista->x);
  66. lista=lista->nast;
  67.  
  68. }
  69. /* while(lista)
  70. {
  71. lista=lista->nast;
  72. if(lista->nast == 0)
  73. {
  74. while(lista->poprz != 0)
  75. {
  76. printf("%c",lista->x);
  77. lista=lista->poprz;
  78. }
  79. break;
  80. }
  81.  
  82. } */
  83.  
  84. palindrom(temp);
  85. }
Add Comment
Please, Sign In to add comment