public SingleLinkedList(int[] data) { Node p; first = null; for (int i=0;i<data.Length;i++){ p = new Node(data[i],first); first = p; } }
public object Clone() { Node p = this.Link; Node First; Node last; First = new Node(this.Info,null); last = First; while (p!=null){ last.Link = new Node(p.Info,null); last = last.Link; p = p.Link; } return First; }
/// <summary> /// /// </summary> /// <param name="data">строка вида 1 2 3 4 5 6</param> public SingleLinkedList(string data) { string[] sa = data.Split(' '); int[] a = new int[sa.Length]; for (int i = 0; i<sa.Length; i++){ a[i] = int.Parse(sa[i]); } Node last; if (a.Length == 0) first = null; else { First = new Node(a[0],null); last = First; for (int i=1;i<a.Length;i++){ last.Link = new Node(a[i],null); last = last.Link; } } }
public void InsertAfterLast(int d) { if (first!=null){ Node p = first; while (p.Link!=null){ p = p.Link; } p.Link = new Node(d,null); } else first = new Node(d,null); }
public void InsertAfter(Node p,int d) { if (p!=null) { p.Link = new Node(d,p.Link); } }
public Node DeleteFirstAndGet() { Node p = first; if (first!=null) first = first.Link; return p; }
/* public void Create2(int[] data){ Node p = new Node(int[] data); first = p; Node last = p; last.Link = null; for (int i=1;i<data.Length;i++){ Node p = new Node(data[i],null); last.Link = p; last = p; } } */ public void DeleteFirst() { if (first!=null){ first = first.Link; } }
public Node DeleteAfterAndGet(Node p) { Node Q = null; if (p!=null && p.Link!=null){ Q = p.Link; p.Link = Q.Link; } return Q; }
public void DeleteAfter(Node p) { if(p!=null && p.Link!=null){ p.Link = p.Link.Link; } }
public void Create(int[] data) { Node last; if (data.Length == 0) first = null; else { First = new Node(data[0],null); last = First; for (int i=1;i<data.Length;i++){ last.Link = new Node(data[i],null); last = last.Link; } } }
public Node(int d, Node l) { Info = d; Link = l; }