Advertisement
J00ker

Untitled

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