Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace OnceNoviembre
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("masukkan nomor: ");
- int number = Convert.ToInt32(Console.ReadLine());
- Fibonacci(0, 1, 1, number);
- Console.ReadKey();
- Stack st = new Stack();
- st.Push(1);
- st.Push(2);
- st.Push(3);
- Console.WriteLine(); Console.WriteLine();
- Console.WriteLine("Pilha");
- foreach (Object obj in st)
- {
- Console.WriteLine(obj);
- }
- Console.WriteLine("Jumlah elemen dalam stack: " + st.Count);
- Console.WriteLine("Apakah tumpukan berisi elemen 3? = " + st.Contains(3));
- Console.ReadKey();
- Console.WriteLine(); Console.WriteLine();
- Console.WriteLine("Fila");
- Queue qt = new Queue();
- qt.Enqueue(1);
- qt.Enqueue(2);
- qt.Enqueue(3);
- foreach (Object obj in qt)
- {
- Console.WriteLine(obj);
- }
- Console.WriteLine();
- Console.WriteLine("The number of elements in the Queue " + qt.Count);
- Console.WriteLine("Does the Queue contain " + qt.Contains(3));
- Console.ReadKey();
- Console.WriteLine(); Console.WriteLine();
- Console.WriteLine("Fila Prioridade");
- PriorityQueue PQ = new PriorityQueue();
- PQ.push(3, " Clear drains");
- PQ.push(4, " Feed cat");
- PQ.push(5, " Make tea");
- PQ.push(1, " Solve RC tasks");
- PQ.push(2, " Tax return");
- while (!PQ.Empty)
- {
- var Val = PQ.pop();
- Console.WriteLine(Val[0] + " : " + Val[1]);
- }
- Console.ReadKey();
- }
- public class PriorityQueue
- {
- private System.Collections.SortedList PseudoQueue;
- public bool Empty
- {
- get
- {
- return PseudoQueue.Count == 0;
- }
- }
- public PriorityQueue()
- {
- PseudoQueue = new System.Collections.SortedList();
- }
- public void push(object Priority, object Value)
- {
- PseudoQueue.Add(Priority, Value);
- }
- public object[] pop()
- {
- object[] ReturnValue = { null, null };
- if (PseudoQueue.Count > 0)
- {
- ReturnValue[0] = PseudoQueue.GetKey(0);
- ReturnValue[1] = PseudoQueue.GetByIndex(0);
- PseudoQueue.RemoveAt(0);
- }
- return ReturnValue;
- }
- }
- public static void Fibonacci(int a, int b, int counter, int number)
- {
- Console.WriteLine(a);
- if (counter < number) Fibonacci(b, a + b, counter + 1, number);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement