Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nod
- {
- int info;
- nod *ante, *urm;
- };
- struct lista
- {
- nod *prim, *ultim;
- };
- void init(lista &c)
- {
- c.prim = c.ultim = NULL;
- }
- void push(lista &c, nod *&start, int x)
- {
- nod *p = new nod;
- p->info = x;
- p->ante = p->urm = NULL;
- if(c.prim == NULL)
- {
- c.prim = c.ultim = p;
- start->urm = p;
- p->ante = start;
- p->urm = start;
- }
- else
- {
- c.ultim->urm = p;
- p->ante = c.ultim;
- p->urm = start;
- c.ultim = p;
- }
- }
- void pop(lista c, nod *start, int x)
- {
- nod *r = start;
- r = r->urm;
- while(r != start && x != r->info)
- r = r->urm;
- if(r != start)
- {
- r->ante->urm = r->urm;
- r->urm->ante = r->ante;
- delete r;
- }
- }
- void afis_lista(lista c, nod *start)
- {
- nod *r = start;
- r = r->urm;
- while(r != start)
- {
- cout << r->info << ' ';
- r = r->urm;
- }
- cout << "\n";
- }
- int main()
- {
- lista c;
- init(c);
- nod *start = new nod;
- start->urm = NULL;
- start->urm = c.prim;
- push(c, start, 3);
- push(c, start, 4);
- push(c, start, 5);
- push(c, start, 9);
- afis_lista(c, start);
- pop(c, start, 3);
- pop(c, start, 5);
- pop(c, start, 4);
- afis_lista(c, start);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement