Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nod{
- int info;
- nod *anterior;
- nod *urmator;
- };
- nod *creare (nod* &ultim){
- nod *prim=new nod;
- int n;
- cin>>n;
- if (n==0)
- return 0;
- else{
- prim->info=n;
- prim->anterior=NULL;
- nod *p=prim;
- cin>>n;
- while (n){
- nod *q=new nod;
- q->info=n;
- q->anterior=p;
- p->urmator=q;
- p=q;
- cin>>n;
- }
- p->urmator=NULL;
- ultim=p;
- return prim;
- }
- }
- void parcurgere_normal(nod *p){
- while (p){
- cout<<p->info<<endl;
- p=p->urmator;
- }
- }
- void parcurgere_invers(nod *p){
- while (p){
- cout<<p->info<<endl;
- p=p->anterior;
- }
- }
- int main()
- {
- nod *ultim, *prim;
- prim=creare(ultim);
- cout<<"Lista parcursa normal este"<<endl;
- parcurgere_normal(prim);
- cout<<endl;
- cout<<"Lista parcursa invers este"<<endl;
- parcurgere_invers (ultim);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement