{
using System;
{
private Node first = null;
private int count = 0;
Property Procedures do not accept any parameters. Note the diff in the function definition (no parenthesis)
*******************************************************************************************************************/
{
/*******************************************
Property Get Procedure
********************************************/
get
{
return (first == null);
}
}
{
/*******************************************
Property Get Procedure
********************************************/
get
{
return count;
}
}
{
if (first == null)
{
throw new InvalidOperationException ("Cant pop from an empty stack");
}
else
{
object temp = first.Value;
first = first.Next;
count–;
return temp;
}
}
{
first = new Node(o, first);
count++;
}
{
public Node Next;
public object Value;
{
Next = next;
Value = value;
}
}
}
{
static void Main()
{
Stack s = new Stack();
Console.WriteLine("Stack is Empty");
else
Console.WriteLine("Stack is not Empty");
s.Push(i);
for (int i = 0; i < 5; i++)
Console.WriteLine("Popped Item is {0} and the count is {1}", s.Pop(), s.Count);
}
}
}
Items in Stack 5
Popped Item is 4 and the count is 4
Popped Item is 3 and the count is 3
Popped Item is 2 and the count is 2
Popped Item is 1 and the count is 1
Popped Item is 0 and the count is 0