Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class QueueTest : MonoBehaviour {
- // Use this for initialization
- void Start ()
- {
- Queue<string> studentNames = new Queue<string> ();
- studentNames.Enqueue ("Tory");
- studentNames.Enqueue ("Gabby");
- studentNames.Enqueue ("Gordy");
- studentNames.Enqueue ("Julian");
- while (studentNames.Count > 0)
- {
- Debug.Log (studentNames.Dequeue() );
- }
- Stack<string> studentNameStack = new Stack<string> ();
- studentNameStack.Push ("Tory");
- studentNameStack.Push ("Tory");
- studentNameStack.Push ("Tory");
- studentNameStack.Push ("Tory");
- while (studentNameStack.Count > 0)
- {
- Debug.Log ( studentNameStack.Pop ());
- }
- List<string> players = new List<string>{"Tory",
- "Gabby",
- "Caroline",
- "Jonathan",
- "Brandon",
- "Kimberly",
- "Julian",
- "Gordy",
- "Campbell",
- "Jacob"};
- Debug.Log (SimulateHotPotato (players, 1034));
- }
- //numberOfTurns == Random.Range(10, 1000);
- string SimulateHotPotato (List<string> names, int numberOfTurns )
- {
- Queue<string> simulationQueue = new Queue<string> ();
- foreach (string name in names)
- {
- simulationQueue.Enqueue (name);
- }
- while (simulationQueue.Count > 1)
- {
- for (int i = 0; i < numberOfTurns; i++)
- {
- simulationQueue.Enqueue (simulationQueue.Dequeue ());
- }
- simulationQueue.Dequeue ();
- }
- return simulationQueue.Dequeue ();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement