Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct nod {
- int info;
- nod *leg;
- };
- nod* creare(int n);
- int main()
- {
- int n; cout<<"n="; cin>>n;
- cout<<"Introdu elemente:"<<endl;
- nod *prim=creare(n);
- nod *p, *q;
- q=p=prim;
- int k; cout<<"k="; cin>>k;
- cout<<"Ordinea este:"<<endl;
- while (n>=1){
- int ind=1;
- while (ind<k-1){
- ind++;
- q=q->leg->leg;
- p=p->leg;
- }
- cout<<p->leg->info<<endl;
- delete p->leg;
- n--;
- p->leg=q;
- p=q;
- }
- return 0;
- }
- nod* creare (int n){
- nod *prim=new nod;
- cin>>prim->info;
- nod *p=prim;
- for (int i=2; i<=n; i++){
- nod *q=new nod;
- cin>>q->info;
- p->leg=q;
- p=q;
- }
- p->leg=prim;
- return prim;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement