Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Vezba_03_2017
- {
- class StackLNode
- {
- public StackLNode(int content)
- {
- Content = content;
- }
- public int Content { get; set; }
- public StackLNode next { get; set; }
- }
- class StackL
- {
- private StackLNode _head;
- private int count = 0;
- public bool IsEmpty
- {
- get { return _head == null; }
- }
- public int Count { get { return count; } set { count = value; } }
- public void Push(int x)
- {
- StackLNode newNode = new StackLNode(x);
- newNode.next = _head;
- _head = newNode;
- count++;
- }
- public int Pop()
- {
- if (IsEmpty)
- throw new InvalidOperationException("The stack is empty.");
- int x = _head.Content;
- _head = _head.next;
- count--;
- return x;
- }
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder();
- StackLNode node = _head;
- while (node != null)
- {
- sb.AppendFormat("{0} ", node.Content);
- node = node.next;
- }
- return sb.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment