Esempio n. 1
0
        public void InsertNode(T a)
        {
            if (start == null)
            {
                start = new SNode <T>(a);
                length++;
                return;
            }
            SNode <T> current = start;

            while (current.Next != null)
            {
                current = current.Next;
            }
            current.Next = new SNode <T>(a);
            length++;
        }
Esempio n. 2
0
        public void InsertNode(T a, int i)
        {
            SNode <T> current;
            SNode <T> previous;

            if (i < 1 || i > length + 1)
            {
                Console.WriteLine("Position is error!");
                return;
            }
            SNode <T> newnode = new SNode <T>(a);

            if (i == 1)
            {
                newnode.Next = start;
                start        = newnode;
                length++;
                return;
            }
            current  = start;
            previous = null;
            int j = 1;

            while (current != null && j < i)
            {
                previous = current;
                current  = current.Next;
                j++;
            }
            if (j == i)
            {
                previous.Next = newnode;
                newnode.Next  = current;
                length++;
            }
        }
Esempio n. 3
0
        public T SearchNode(T value)
        {
            if (IsEmpty())
            {
                Console.WriteLine("List is empty!");
                return(default(T));
            }
            SNode <T> current = start;
            int       i       = 1;

            while (!current.Data.ToString().Contains(value.ToString()) && current != null)
            {
                current = current.Next;
                i++;
            }
            if (current != null)
            {
                return(current.Data);
            }
            else
            {
                return(default(T));
            }
        }
Esempio n. 4
0
 public SLinkList()
 {
     start = null;
 }
Esempio n. 5
0
 public SNode()
 {
     data = default(T);
     next = null;
 }
Esempio n. 6
0
 public SNode(T val)
 {
     data = val;
     next = null;
 }
Esempio n. 7
0
 public void Clear()
 {
     start = null;
 }
Esempio n. 8
0
 public SNode(SNode <T> p)
 {
     next = p;
 }
Esempio n. 9
0
 public SNode(T val, SNode <T> p)
 {
     data = val;
     next = p;
 }