//出栈 public void Pop() { if (IsEmpty()) { Console.WriteLine("The LinkStack is empty,you can not remove element!"); return; } LinkStackNode <T> p = new LinkStackNode <T>(); p = top.Next; top = p; num--; }
//入栈 public void Push(T item) { LinkStackNode <T> p = new LinkStackNode <T>(item); if (top == null) { top = p; } else { p.Next = top; top = p; } num++; }
//进制转换,10进制数转换为8进制数 public int Conversion(int n) { LinkStack1 <int> a = new LinkStack1 <int>(); int i = 0; while (n != 0) { i = n % 8; n = n / 8; a.Push(i); } int num = a.Num; int temp = 0; LinkStackNode <int> p = a.Top; while (p != null && num - 1 >= 0) { temp += p.Data * (int)Math.Pow(10, num - 1); p = p.Next; num--; } return(temp); }
public LinkStackNode() { this.data = default(T); this.next = null; }
public LinkStackNode(LinkStackNode <T> n) { this.data = default(T); this.next = n; }
public LinkStackNode(T val) { this.data = val; this.next = null; }
//构造 public LinkStackNode(T val, LinkStackNode <T> n) { this.data = val; this.next = n; }
//清空链栈 public void Clear() { top = null; num = 0; }
//构造 public LinkStack1() { top = null; num = 0; }