Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- ifstream f("date.in");
- struct nod
- {
- int info;
- nod *st,*dr;
- };
- nod *prim,*ultim;
- void creare()
- {
- nod *nou;
- int x;
- while (f>>x)
- if (prim==NULL)
- {
- prim=new nod;
- prim->info=x;
- prim->st=NULL;
- ultim=prim;
- }
- else
- {
- nou=new nod;
- nou->info=x;
- ultim->dr=nou;
- nou->st=ultim;
- ultim=nou;
- }
- ultim->dr=NULL;
- }
- void parcurgere_st_dr()
- {
- nod *p=prim;
- while (p)
- {
- cout<<p->info<<" ";
- p=p->dr;
- }
- }
- void parcurgere_dr_st()
- {
- nod *p=ultim;
- while (p)
- {
- cout<<p->info<<" ";
- p=p->st;
- }
- }
- int main()
- {
- creare();
- parcurgere_st_dr();
- cout<<'\n';
- parcurgere_dr_st();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement