Advertisement
Dani_info

Lista circulara

Oct 28th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct nod {
  6.     int info;
  7.     nod *leg;
  8. };
  9.  
  10. nod* creare(int n);
  11.  
  12. int main()
  13. {
  14.     int n; cout<<"n="; cin>>n;
  15.     cout<<"Introdu elemente:"<<endl;
  16.     nod *prim=creare(n);
  17.     nod *p, *q;
  18.     q=p=prim;
  19.     int k; cout<<"k="; cin>>k;
  20.     cout<<"Ordinea este:"<<endl;
  21.     while (n>=1){
  22.         int ind=1;
  23.         while (ind<k-1){
  24.             ind++;
  25.             q=q->leg->leg;
  26.             p=p->leg;
  27.         }
  28.         cout<<p->leg->info<<endl;
  29.         delete p->leg;
  30.         n--;
  31.         p->leg=q;
  32.         p=q;
  33.     }
  34.     return 0;
  35. }
  36.  
  37. nod* creare (int n){
  38.     nod *prim=new nod;
  39.     cin>>prim->info;
  40.     nod *p=prim;
  41.     for (int i=2; i<=n; i++){
  42.         nod *q=new nod;
  43.         cin>>q->info;
  44.         p->leg=q;
  45.         p=q;
  46.     }
  47.     p->leg=prim;
  48.     return prim;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement