Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace OnceNoviembre
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. Console.Write("masukkan nomor: ");
  15. int number = Convert.ToInt32(Console.ReadLine());
  16. Fibonacci(0, 1, 1, number);
  17. Console.ReadKey();
  18.  
  19. Stack st = new Stack();
  20. st.Push(1);
  21. st.Push(2);
  22. st.Push(3);
  23. Console.WriteLine(); Console.WriteLine();
  24.  
  25. Console.WriteLine("Pilha");
  26. foreach (Object obj in st)
  27. {
  28.  
  29. Console.WriteLine(obj);
  30. }
  31.  
  32. Console.WriteLine("Jumlah elemen dalam stack: " + st.Count);
  33. Console.WriteLine("Apakah tumpukan berisi elemen 3? = " + st.Contains(3));
  34. Console.ReadKey();
  35. Console.WriteLine(); Console.WriteLine();
  36.  
  37. Console.WriteLine("Fila");
  38. Queue qt = new Queue();
  39. qt.Enqueue(1);
  40. qt.Enqueue(2);
  41. qt.Enqueue(3);
  42.  
  43. foreach (Object obj in qt)
  44. {
  45. Console.WriteLine(obj);
  46. }
  47. Console.WriteLine();
  48. Console.WriteLine("The number of elements in the Queue " + qt.Count);
  49. Console.WriteLine("Does the Queue contain " + qt.Contains(3));
  50. Console.ReadKey();
  51. Console.WriteLine(); Console.WriteLine();
  52.  
  53. Console.WriteLine("Fila Prioridade");
  54. PriorityQueue PQ = new PriorityQueue();
  55. PQ.push(3, " Clear drains");
  56. PQ.push(4, " Feed cat");
  57. PQ.push(5, " Make tea");
  58. PQ.push(1, " Solve RC tasks");
  59. PQ.push(2, " Tax return");
  60.  
  61. while (!PQ.Empty)
  62. {
  63. var Val = PQ.pop();
  64. Console.WriteLine(Val[0] + " : " + Val[1]);
  65. }
  66. Console.ReadKey();
  67.  
  68.  
  69. }
  70.  
  71. public class PriorityQueue
  72. {
  73. private System.Collections.SortedList PseudoQueue;
  74.  
  75. public bool Empty
  76. {
  77. get
  78. {
  79. return PseudoQueue.Count == 0;
  80. }
  81. }
  82.  
  83. public PriorityQueue()
  84. {
  85. PseudoQueue = new System.Collections.SortedList();
  86. }
  87.  
  88. public void push(object Priority, object Value)
  89. {
  90. PseudoQueue.Add(Priority, Value);
  91. }
  92.  
  93. public object[] pop()
  94. {
  95. object[] ReturnValue = { null, null };
  96. if (PseudoQueue.Count > 0)
  97. {
  98. ReturnValue[0] = PseudoQueue.GetKey(0);
  99. ReturnValue[1] = PseudoQueue.GetByIndex(0);
  100.  
  101. PseudoQueue.RemoveAt(0);
  102. }
  103. return ReturnValue;
  104. }
  105.  
  106. }
  107. public static void Fibonacci(int a, int b, int counter, int number)
  108. {
  109. Console.WriteLine(a);
  110. if (counter < number) Fibonacci(b, a + b, counter + 1, number);
  111. }
  112.  
  113. }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement