using System;
public class Program
{
public static void Main()
Console.WriteLine("Hello World");
}
public class Node<T>
private T value;
private Node<T> next;
/* הפעולה בונה ומחזירה חוליה שהערך שלה הוא info ואין לה חוליה עוקבת **/
public Node(T info)
this.value = value;
this.next = null;
/*הפעולה בונה ומחזירה חוליה, שהערך שלה הוא info
והחוליה העוקבת לה היא החוליה next */
public Node(T info, Node<T> next)
this.next = next;
/* הפעולה מחזירה את הערך של החוליה הנוכחית **/
public T Getc()
return value;
/* הפעולה מחזירה את החוליה העוקבת לחוליה הנוכחית **/
public Node<T> GetNext()
return next;
/* הפעולה קובעת את ערך החוליה הנוכחית להיות info **/
public void SetInfo(T info)
/* הפעולה קובעת את החוליה העוקבת לחוליה הנוכחית להיות החוליה next **/
public void SetNext(Node<T> next)
/* הפעולה מחזירה מחרוזת המתארת את החוליה הנוכחית */
public String ToString()
return this.value.toString();
public class Stack<T>
private Node<T> head;
/* הפעולה בונה ומחזירה מחסנית ריקה **/
public Stack()
this.head = null;
public void Push(T x)
Node<T> temp = new Node<T>(x);
temp.SetNext(head);
head = temp;
/* הפעולה מכניסה את הערך x לראש המחסנית הנוכחית **/
/* הפעולה מוציאה ומחזירה את הערך הנמצא בראש המחסנית הנוכחית **/
public T Pop()
T x = head.GetValue();
head = head.GetNext();
return x;
/* הפעולה מחזירה את הערך הנמצא בראש המחסנית הנוכחית **/
public T Top()
return head.GetValue();
/* הפעולה מחזירה 'אמת' אם המחסנית הנוכחית ריקה, ומחזירה 'שקר' אחרת **/
public bool IsEmpty()
return head == null;
/* הפעולה מחזירה מחרוזת המתארת את המחסנית הנוכחית */
String s = "[";
Node<T> p = this.head;
while (p != null)
s = s + p.GetValue().ToString();
if (p.GetNext() != null)
s = s + ",";
p = p.GetNext();
s = s + "]";
return s;