Cod sursa(job #2423976)

Utilizator AndreiJJIordan Andrei AndreiJJ Data 22 mai 2019 13:20:10
Problema A+B Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.98 kb
struct Nod
{
    int info;
    Nod *st, *dr;
};
Nod *L, *U;

void Creare(int x)
{
    L = new Nod;
    U = L;
    L->st = l->dr = NULL;
    L->info = x;
}

void InsInainte(Nod *p, int x)
{
    Nod *q = new Nod;
    q->info = x;
    q->dr = p;
    q->st = p->st;
    p->st->dr = q;
    p->st = q;
}
void InsInceput(int x)
{
    Nod *p = new Nod;
    p->info = x;
    p->dr = L;
    p->st = NULL;
    L->st = p;
    L = p;
}
void Sterge(Nod *p)
{
    if(L == NULL)
        return;
    if(L == U)
    {
        delete L;
        L = U = NULL;
        return;
    }
    if(p == L)
    {
        L = L->dr;
        delete p;
        l->st = NULL;
        return;
    }
    if(p == U)
    {
        U = U->st;
        delete p;
        U->dr = NULL;
        return;
    }
    p->st->dr = p->dr;
    p->dr->st = p->st;
    delete p;
}

void Parc()
{
    for(Nod *p=L; p != NULL; p = p->dr)
        cout << p->info << " ";
    cout << "\n";
}