Exemplo n.º 1
0
        public T SearchNode(int i)
        {
            if (IsEmpty())
            {
                Console.WriteLine("List is empty!!");
                return(default(T));
            }
            CityNode <T> current = start;
            int          j       = 1;

            while (current.Next != null && j < i)
            {
                current = current.Next;
                j++;
            }
            if (j == i)
            {
                return(current.Data);
            }
            else
            {
                Console.WriteLine("The node isn't exist!!");
                return(default(T));
            }
        }
Exemplo n.º 2
0
        public void DeleteNode(int i)
        {
            if (IsEmpty() || i < 1 || i > GetLength())
            {
                Console.WriteLine("Link is empty or position is error!");
            }
            CityNode <T> current = start;

            if (i == 1)
            {
                start = current.Next;
                length--;
                return;
            }
            CityNode <T> previous = null;
            int          j        = 1;

            while (current != null && j < i)
            {
                previous = current;
                current  = current.Next;
                j++;
            }
            if (j == i)
            {
                previous.Next = current.Next;
                length--;
            }
            else
            {
                Console.WriteLine("The node isn't exist!!");
            }
        }
Exemplo n.º 3
0
        public void Display()
        {
            CityNode <T> p = new CityNode <T>();

            p = this.start;
            while (p != null)
            {
                Console.Write(p.Data.ToString() + " ");
                p = p.Next;
            }
        }
Exemplo n.º 4
0
        public T ReturnPoint()
        {
            CityNode <T> current = start;

            Console.Write("请输入城市名称:");
            string cityname = Convert.ToString(Console.ReadLine());

            while (current.Data.ToString().Contains(cityname))
            {
                Console.WriteLine("{0}", current.Data.ToString());
                return(default(T));
            }
            return(default(T));
        }
Exemplo n.º 5
0
        public void InsertNode(T a)
        {
            if (start == null)
            {
                start = new CityNode <T>(a);
                length++;
                return;
            }
            CityNode <T> current = start;

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

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

            if (i == 1)
            {
                newnode.Next = start;
                start        = newnode;
                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++;
            }
        }
Exemplo n.º 7
0
        public T SearchNode(T value)
        {
            if (IsEmpty())
            {
                Console.WriteLine("List is empty!!");
                return(default(T));
            }
            CityNode <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));
            }
        }
Exemplo n.º 8
0
 public void Clear()
 {
     start = null;
 }
Exemplo n.º 9
0
 public CityList()
 {
     start = null;
 }
Exemplo n.º 10
0
 public CityNode()
 {
     data = default(T);
     next = null;
 }
Exemplo n.º 11
0
 public CityNode(T val)
 {
     data = val;
     next = null;
 }
Exemplo n.º 12
0
 public CityNode(CityNode <T> p)
 {
     next = p;
 }
Exemplo n.º 13
0
 private CityNode <T> next; //引用域
 //private T a;
 public CityNode(T val, CityNode <T> p)
 {
     data = val;
     next = p;
 }