Ejemplo n.º 1
0
        public void add(Person p)
        {
            Node wt = new Node(p);
            Node nt = new Node(p);
            Node current = wHead;
            Node prev = null;

            //weight sorting loop
            while (current != null && current.person.Weight < p.Weight)
            {
                prev = current;
                current = current.nextNode;
            }

            if (prev == null)
            {
                wt.nextNode = wHead;
                wHead = wt;
            }
            else
            {
                wt.nextNode = current;
                prev.nextNode = wt;
            }

            //name sorting loop
            current = nHead;
            prev = null;

            while (current != null && String.Compare(current.person.Name, p.Name) < 0)
            {
                prev = current;
                current = current.nextNode;
            }

            if (prev == null)
            {
                nt.nextNode = nHead;
                nHead = nt;
            }
            else
            {
                nt.nextNode = current;
                prev.nextNode = nt;
            }

            size++;
        }
Ejemplo n.º 2
0
        //deletes the first occurence of query in the sorted name list.
        public void delete(String name)
        {
            if (nHead == null)
            {
                Console.WriteLine("List is empty");
                return;
            }

            Node current = nHead;
            Node prev = null;
            while (current != null)
            {
                if (current.person.Name.Equals(name))
                {
                    if (current == nHead)
                        nHead = nHead.nextNode;
                    else
                        prev.nextNode = current.nextNode;

                    return;
                }

                prev = current;
                current = current.nextNode;
            }

            if(current == null)
                Console.WriteLine(name + " cannot be found.");
        }
Ejemplo n.º 3
0
 public DLinkList()
 {
     wHead = null;
     nHead = null;
     size = 0;
 }
Ejemplo n.º 4
0
        //deletes the first occurence of the query in the sorted weight list.
        public void delete(int weight)
        {
            if (wHead == null)
            {
                Console.WriteLine("List is empty");
                return;
            }

            Node current = wHead;
            Node prev = null;
            while (current != null)
            {
                if (current.person.Weight == weight)
                {
                    if (current == wHead)
                        wHead = wHead.nextNode;
                    else
                        prev.nextNode = current.nextNode;

                    return;
                }

                prev = current;
                current = current.nextNode;
            }

            if (current == null)
                Console.WriteLine(weight + " cannot be found.");
        }