Advertisement
Dani_info

intoarecere lista

Oct 29th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. struct nod{
  7.     int info;
  8.     nod *leg;
  9. };
  10.  
  11. nod* creare(){
  12.     int n;
  13.     cin>>n;
  14.     if(n==0) return 0;
  15.     else{
  16.         nod *p;
  17.         nod *prim=new nod;
  18.         prim->info=n;
  19.         p=prim;
  20.         cin>>n;
  21.         while (n){
  22.             nod *q=new nod;
  23.             q->info=n;
  24.             p->leg=q;
  25.             p=q;
  26.             cin>>n;
  27.         }
  28.         p->leg=NULL;
  29.         return prim;
  30.     }
  31. }
  32.  
  33. void parcuregre (nod *prim){
  34.     while (prim){
  35.         cout<<prim->info<<endl;
  36.         prim=prim->leg;
  37.     }
  38. }
  39.  
  40. nod *intoarecere (nod *prim){
  41.     nod *anterior, *urmator, *curent;
  42.     nod *p=prim;
  43.     curent=p->leg;
  44.     prim->leg=NULL;
  45.     anterior=p;
  46.     while (curent){
  47.         urmator=curent->leg;
  48.         curent->leg=anterior;
  49.         anterior=curent;
  50.         curent=urmator;
  51.     }
  52.     return anterior;
  53. }
  54. int main()
  55. {
  56.     nod *p=creare();
  57.     nod *q=intoarecere(p);
  58.     parcuregre(q);
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement