Advertisement
J00ker

Untitled

Jun 11th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.76 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. struct Nod
  7. {
  8.     int info;
  9.     Nod *stg, *drp;
  10. };
  11.  
  12. Nod *head, *tail;
  13.  
  14. void Init()
  15. {
  16.     head = tail = NULL;
  17. }
  18.  
  19. void Creare(int x)
  20. {
  21.     head = new Nod;
  22.     head -> info = x;
  23.     head -> drp = NULL;
  24.     head -> stg = NULL;
  25.     tail = head;
  26. }
  27.  
  28. void AdInceput(int x)
  29. {
  30.     Nod *p;
  31.     p = new Nod;
  32.     p -> info = x;
  33.     p -> drp = head;
  34.     p -> stg = NULL;
  35.     head -> stg = p;
  36.     head = p;
  37. }
  38.  
  39. void AdSfarsit(int x)
  40. {
  41.     Nod *p;
  42.     p = new Nod;
  43.     p -> info = x;
  44.     p -> stg = tail;
  45.     p -> drp = NULL;
  46.     tail -> drp = p;
  47.     tail = p;
  48. }
  49.  
  50. void AdDupaNod(Nod *p, int x)
  51. {
  52.     Nod *q;
  53.     q = new Nod;
  54.     q -> info = x;
  55.     q -> stg = p;
  56.     q -> drp = p -> drp;
  57.     p -> drp = q;
  58.     p -> drp -> stg = q;
  59. }
  60.  
  61. void ParcSD()
  62. {
  63.     for(Nod *p = head; p != NULL; p = p -> drp)
  64.         cout << p -> info << " ";
  65.     cout << "\n";
  66. }
  67.  
  68. void ParcDS()
  69. {
  70.     for(Nod *p = tail; p != NULL; p = p -> stg)
  71.         cout << p -> info << " ";
  72.     cout << "\n";
  73. }
  74.  
  75. Nod *Cautare(int x)
  76. {
  77.     for(Nod *p = head; p != NULL; p = p -> drp)
  78.         if(p -> info == x) return p;
  79.     return NULL;
  80. }
  81.  
  82. void StInterior(Nod *p)
  83. {
  84.     p -> stg -> drp = p -> drp;
  85.     p -> drp -> stg = p -> stg;
  86.     delete p;
  87. }
  88.  
  89. void StInceput()
  90. {
  91.     Nod *p = head;
  92.     p -> drp -> stg = NULL;
  93.     head = head -> drp;
  94.     delete p;
  95. }
  96.  
  97. void StSfarsit()
  98. {
  99.     Nod *p = tail;
  100.     p -> stg -> drp = NULL;
  101.     tail = tail -> stg;
  102.     delete p;
  103. }
  104.  
  105. int Palindrom()
  106. {
  107.     Nod *p, *q;
  108.     q = tail;
  109.     for(p = head; (p != q) && (p -> st != q); )
  110.     {
  111.         if(p -> info != q -> info)
  112.             return 0;
  113.         p = p -> drp;
  114.         q = q -> stg;
  115.     }
  116.     return 1;
  117. }
  118.  
  119. int main()
  120. {
  121.     int n, x;
  122.     ifstream fin("fis.in");
  123.     fin >> n >> x;
  124.     Creare(x);
  125.     for(int i = 2; i <= n; i++)
  126.     {
  127.         fin >> x;
  128.         AdSfarsit(x);
  129.     }
  130.     ParcSD();
  131.  
  132.     /*
  133.     Nod *in, *sf;
  134.     in = head;
  135.     for(int i = 1; i <= n/2; i++)
  136.         in = in -> drp;
  137.     if(n % 2 == 0)
  138.         sf = in -> drp;
  139.     else
  140.         sf = in;
  141.  
  142.     int f = 1;
  143.     while((in != NULL) && (sf != NULL) && f)
  144.     {
  145.         if(in -> info != sf -> info)
  146.             f = 0;
  147.         in = in -> stg;
  148.         sf = sf -> drp;
  149.     }
  150.     if(f)
  151.         cout << "Palnidrom.\n\n";
  152.     else
  153.         cout << "NePalnidrom.\n\n";
  154.     /*
  155.  
  156.     /*
  157.     Nod *in, *sf;
  158.     in = head; sf = tail;
  159.     int f = 1;
  160.     for(int i = 1; (i <= n/2) && f; i++)
  161.     {
  162.         if(in -> info != sf -> info)
  163.             f = 0;
  164.         in = in -> drp;
  165.         sf = sf -> stg;
  166.     }
  167.     if(f)
  168.         cout << "Palnirdom.\n\n";
  169.     else
  170.         cout << "NePalnirdom.\n\n";
  171.     */
  172.  
  173.     return 0;
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement