Advertisement
ntamas

stack és queue

Feb 3rd, 2014
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. /*
  2. last in first out -> Stack
  3. first in first out -> Queue
  4. */
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10.  
  11. namespace ConsoleApplication1
  12. {
  13.   class Program
  14.   {
  15.     static void kiirat2(Queue<int> s)
  16.     {
  17.       foreach (int x in s)
  18.       {
  19.         Console.Write("{0} ", x);
  20.       }
  21.     }
  22.     static void kiirat(Stack<int> s)
  23.     {
  24.       foreach(int x in s)
  25.       {
  26.         Console.Write("{0} ", x);
  27.       }
  28.     }
  29.     static void Main(string[] args)
  30.     {
  31.       Stack<int> stack = new Stack<int>();
  32.       Queue<int> queue = new Queue<int>();
  33.       stack.Push(13);
  34.       stack.Push(16);
  35.       stack.Push(19);
  36.       stack.Push(25);
  37.       stack.Push(26);
  38.       stack.Push(48);
  39.       stack.Push(78);
  40.       stack.Push(794);
  41.       kiirat(stack);
  42.       Console.WriteLine();
  43.       int a = stack.Pop();
  44.       kiirat(stack);
  45.       Console.WriteLine();
  46.       int b = stack.Peek();
  47.       Console.WriteLine(b);
  48.       queue.Enqueue(14);
  49.       queue.Enqueue(16);
  50.       queue.Enqueue(17);
  51.       queue.Enqueue(18);
  52.       queue.Enqueue(19);
  53.       kiirat2(queue);
  54.       Console.WriteLine();
  55.       queue.Dequeue();
  56.       kiirat2(queue);
  57.       int c = queue.Peek();
  58.       Console.WriteLine();
  59.       Console.WriteLine(c);
  60.       Console.ReadKey();
  61.     }
  62.   }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement