Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _09092019
  8. {
  9. class Program
  10. {
  11.  
  12.  
  13. static void Main(string[] args)
  14. {
  15. Stack zasobnik = new Stack();
  16. zasobnik.Push('c');
  17. zasobnik.Push('b');
  18. zasobnik.Push('f');
  19.  
  20. zasobnik.PrintStack();
  21.  
  22. zasobnik.Pop();
  23.  
  24. Console.WriteLine("pryc");
  25.  
  26. zasobnik.PrintStack();
  27.  
  28. zasobnik.Peek();
  29.  
  30. Console.WriteLine("zustan");
  31.  
  32. zasobnik.PrintStack();
  33. Console.Read();
  34. }
  35. }
  36. class Stack
  37. {
  38. char[] zasobnik = new char[10];
  39. int d = -1;
  40.  
  41. public void Push(char c) => zasobnik[++d] = c;
  42. public void Pop()
  43. {
  44. zasobnik.Reverse();
  45. Console.WriteLine(zasobnik[0]);
  46. List<char> list = new List<char>(zasobnik);
  47. list.RemoveAt(0);
  48. zasobnik = list.ToArray();
  49. zasobnik.Reverse();
  50. }
  51. public void Peek()
  52. {
  53. zasobnik.Reverse();
  54. Console.WriteLine(zasobnik[0]);
  55. }
  56. public void IsEmpty()
  57. {
  58. bool prazdne = zasobnik.Length == 0;
  59. }
  60. public void PrintStack()
  61. {
  62. int i;
  63. for ( i = 0; i < zasobnik.Length; i++)
  64. {
  65. Console.WriteLine(zasobnik[i]);
  66. }
  67. i = 0;
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement