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