Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. public interface IStack
  2. {
  3. char peek();
  4. char pop();
  5. void push(char nytt);
  6. bool isEmpty();
  7. }
  8.  
  9. public class Stack<t> : IStack
  10. {
  11. LinkedList<char> minStack = new LinkedList<char>();
  12.  
  13. public char peek()
  14. {
  15. return minStack.Last.Value;
  16. }
  17.  
  18.  
  19. public char pop()
  20. {
  21. minStack.RemoveLast();
  22.  
  23. return minStack.Last.Value;
  24.  
  25.  
  26.  
  27.  
  28. }
  29.  
  30.  
  31.  
  32. public void push(char nytt)
  33. {
  34. minStack.AddLast(nytt);
  35. }
  36.  
  37. public bool isEmpty()
  38. {
  39.  
  40. if (minStack.Count == 0)
  41. {
  42. return true;
  43.  
  44. }
  45. else
  46. {
  47. return false;
  48.  
  49. }
  50.  
  51. }
  52.  
  53.  
  54. }
  55.  
  56. // something something hรคr (resten av funktionerna)
  57.  
  58.  
  59. static void Main(string[] args)
  60. {
  61. Stack<char> stacken = new Stack<char>();
  62.  
  63. try
  64. {
  65. //stacken.pop();
  66. stacken.push('s'); stacken.push('r');
  67. stacken.push('a'); stacken.push('w');
  68. stacken.push(' ');
  69. stacken.push('r'); stacken.push('a');
  70. stacken.push('t'); stacken.push('s');
  71. }
  72.  
  73. catch (InvalidOperationException e)
  74. {
  75.  
  76. Console.WriteLine(e.Message);
  77. }
  78.  
  79.  
  80.  
  81. while (!stacken.isEmpty())
  82. {
  83. Console.Write(stacken.pop());
  84. }
  85.  
  86. Console.ReadLine();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement