Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class QueueTest : MonoBehaviour {
  6.  
  7. // Use this for initialization
  8. void Start ()
  9. {
  10. Queue<string> studentNames = new Queue<string> ();
  11. studentNames.Enqueue ("Tory");
  12. studentNames.Enqueue ("Gabby");
  13. studentNames.Enqueue ("Gordy");
  14. studentNames.Enqueue ("Julian");
  15.  
  16. while (studentNames.Count > 0)
  17. {
  18. Debug.Log (studentNames.Dequeue() );
  19. }
  20.  
  21. Stack<string> studentNameStack = new Stack<string> ();
  22. studentNameStack.Push ("Tory");
  23. studentNameStack.Push ("Tory");
  24. studentNameStack.Push ("Tory");
  25. studentNameStack.Push ("Tory");
  26.  
  27. while (studentNameStack.Count > 0)
  28. {
  29. Debug.Log ( studentNameStack.Pop ());
  30. }
  31.  
  32. List<string> players = new List<string>{"Tory",
  33. "Gabby",
  34. "Caroline",
  35. "Jonathan",
  36. "Brandon",
  37. "Kimberly",
  38. "Julian",
  39. "Gordy",
  40. "Campbell",
  41. "Jacob"};
  42.  
  43. Debug.Log (SimulateHotPotato (players, 1034));
  44. }
  45.  
  46. //numberOfTurns == Random.Range(10, 1000);
  47.  
  48. string SimulateHotPotato (List<string> names, int numberOfTurns )
  49. {
  50. Queue<string> simulationQueue = new Queue<string> ();
  51.  
  52. foreach (string name in names)
  53. {
  54. simulationQueue.Enqueue (name);
  55. }
  56.  
  57. while (simulationQueue.Count > 1)
  58. {
  59. for (int i = 0; i < numberOfTurns; i++)
  60. {
  61. simulationQueue.Enqueue (simulationQueue.Dequeue ());
  62. }
  63.  
  64. simulationQueue.Dequeue ();
  65. }
  66.  
  67. return simulationQueue.Dequeue ();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement