Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class FindIndex
- {
- static void Main()
- {
- int n = 3;
- int p = 16;
- Queue<int> queue = new Queue<int>();
- queue.Enqueue(n);
- int index = 0;
- while (queue.Count > 0)
- {
- int current = queue.Dequeue();
- index++;
- if (current == p)
- {
- Console.WriteLine("index = {0}", index);
- break;
- }
- queue.Enqueue(current + 1);
- queue.Enqueue(2 * current);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment