Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct Nod
- {
- int info;
- Nod *stg, *drp;
- };
- Nod *head, *tail;
- void Init()
- {
- head = tail = NULL;
- }
- void Creare(int x)
- {
- head = new Nod;
- head -> info = x;
- head -> drp = NULL;
- head -> stg = NULL;
- tail = head;
- }
- void AdInceput(int x)
- {
- Nod *p;
- p = new Nod;
- p -> info = x;
- p -> drp = head;
- p -> stg = NULL;
- head -> stg = p;
- head = p;
- }
- void AdSfarsit(int x)
- {
- Nod *p;
- p = new Nod;
- p -> info = x;
- p -> stg = tail;
- p -> drp = NULL;
- tail -> drp = p;
- tail = p;
- }
- void AdDupaNod(Nod *p, int x)
- {
- Nod *q;
- q = new Nod;
- q -> info = x;
- q -> stg = p;
- q -> drp = p -> drp;
- p -> drp = q;
- p -> drp -> stg = q;
- }
- void ParcSD()
- {
- for(Nod *p = head; p != NULL; p = p -> drp)
- cout << p -> info << " ";
- cout << "\n";
- }
- void ParcDS()
- {
- for(Nod *p = tail; p != NULL; p = p -> stg)
- cout << p -> info << " ";
- cout << "\n";
- }
- Nod *Cautare(int x)
- {
- for(Nod *p = head; p != NULL; p = p -> drp)
- if(p -> info == x) return p;
- return NULL;
- }
- void StInterior(Nod *p)
- {
- p -> stg -> drp = p -> drp;
- p -> drp -> stg = p -> stg;
- delete p;
- }
- void StInceput()
- {
- Nod *p = head;
- p -> drp -> stg = NULL;
- head = head -> drp;
- delete p;
- }
- void StSfarsit()
- {
- Nod *p = tail;
- p -> stg -> drp = NULL;
- tail = tail -> stg;
- delete p;
- }
- int Palindrom()
- {
- Nod *p, *q;
- q = tail;
- for(p = head; (p != q) && (p -> st != q); )
- {
- if(p -> info != q -> info)
- return 0;
- p = p -> drp;
- q = q -> stg;
- }
- return 1;
- }
- int main()
- {
- int n, x;
- ifstream fin("fis.in");
- fin >> n >> x;
- Creare(x);
- for(int i = 2; i <= n; i++)
- {
- fin >> x;
- AdSfarsit(x);
- }
- ParcSD();
- /*
- Nod *in, *sf;
- in = head;
- for(int i = 1; i <= n/2; i++)
- in = in -> drp;
- if(n % 2 == 0)
- sf = in -> drp;
- else
- sf = in;
- int f = 1;
- while((in != NULL) && (sf != NULL) && f)
- {
- if(in -> info != sf -> info)
- f = 0;
- in = in -> stg;
- sf = sf -> drp;
- }
- if(f)
- cout << "Palnidrom.\n\n";
- else
- cout << "NePalnidrom.\n\n";
- /*
- /*
- Nod *in, *sf;
- in = head; sf = tail;
- int f = 1;
- for(int i = 1; (i <= n/2) && f; i++)
- {
- if(in -> info != sf -> info)
- f = 0;
- in = in -> drp;
- sf = sf -> stg;
- }
- if(f)
- cout << "Palnirdom.\n\n";
- else
- cout << "NePalnirdom.\n\n";
- */
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement