Esempio n. 1
0
        public WNode deleteWorker(WNode curr, Weapon item)
        {
            if (curr == null)
            {
                return(curr);
            }
            if (curr.data.weaponName.CompareTo(item.weaponName) > 0)
            {
                curr.left = deleteWorker(curr.left, item);
            }
            if (curr.data.weaponName.CompareTo(item.weaponName) < 0)
            {
                curr.right = deleteWorker(curr.right, item);
            }

            if (curr.data.weaponName.CompareTo(item.weaponName) == 0)
            {
                if (curr.left == null)
                {
                    return(curr.right);
                }
                if (curr.right == null)
                {
                    return(curr.left);
                }
                WNode successor = curr.right;
                while (successor.left != null)
                {
                    successor = successor.left;
                }
                curr.data.weaponName = successor.data.weaponName;
                curr.right           = deleteWorker(curr.right, item);
            }
            return(curr);
        }
Esempio n. 2
0
 public Weapon(string n, int rang, int dam, double w, double c)
 {
     weaponName = n;
     damage     = dam;
     range      = rang;
     weight     = w;
     cost       = c;
     next       = null;
 }
Esempio n. 3
0
        private void inOrderWorker(WNode curr)
        {
            string s = "\nName: \tRange: \tDamage: \tWeight: \tCost:\n";

            if (curr == null)
            {
                return;
            }
            inOrderWorker(curr.left);
            s = s + curr.data.weaponName + "\t" + curr.data.range + "\t" + curr.data.damage + "\t" + curr.data.weight + "\t" + curr.data.cost;
            Console.WriteLine("{0} ", s);
            inOrderWorker(curr.right);
        }
Esempio n. 4
0
 private WNode insertWorker(WNode curr, Weapon item)
 {
     if (curr == null)
     {
         return(new WNode(item));
     }
     if (curr.data.weaponName.CompareTo(item.weaponName) > 0)
     {
         curr.left = insertWorker(curr.left, item);
     }
     if (curr.data.weaponName.CompareTo(item.weaponName) < 0)
     {
         curr.right = insertWorker(curr.right, item);
     }
     return(curr);
 }
Esempio n. 5
0
        public Weapon searchNonRecursion(string n)
        {
            WNode curr = root;

            while (curr != null)
            {
                if (curr.data.weaponName.CompareTo(n) == 0)
                {
                    return(curr.data);
                }
                if (curr.data.weaponName.CompareTo(n) > 0)
                {
                    curr = curr.left;
                }
                else
                {
                    curr = curr.right;
                }
            }
            Console.WriteLine("Cannot find \"" + n + "\" in the list!");
            return(null);
        }
Esempio n. 6
0
 public WNode(Weapon d)
 {
     data = d;
     left = right = null;
 }
Esempio n. 7
0
 public void delete(Weapon item)
 {
     root = deleteWorker(root, item);
 }
Esempio n. 8
0
 public void insert(Weapon item)
 {
     root = insertWorker(root, item);
 }
Esempio n. 9
0
 public BinarySearchTree()
 {
     root = null;
 }