コード例 #1
0
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //if theres only one pellet
            if (headPointer == tailPointer)
            {
                headPointer = null;
                tailPointer = null;
            }

            //if deleting last pellet
            else if (pelletToDelete == tailPointer)
            {
                Pellet pelletWalker = headPointer;
                while (pelletWalker.Next != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }
                tailPointer = pelletWalker;
            }
            // if deleting frist pellet
            else if (headPointer == pelletToDelete)
            {
                headPointer = pelletToDelete.Next;
            }

            //if deleting pellet in linked list longer than 2
            else {
                Pellet pelletWalker = headPointer;
                while (pelletWalker != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }
                pelletWalker = pelletToDelete.Next;
            }
        }
コード例 #2
0
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //If you are deleting the first node
            if (pelletToDelete == headPointer)
            {
                //If it is the only node in the list
                if (Count() == 1)
                {
                    //Head and Tail both become null
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    //Move Head along to the second node
                    headPointer = headPointer.Next;
                }
            }
            else
            {
                Pellet current = headPointer;
                while (current.Next != pelletToDelete)
                {
                    current = current.Next;
                }
                current.Next = pelletToDelete.Next;

                //If you have just deleted the last node in the list
                if (pelletToDelete == tailPointer)
                {
                    //Set Tail to point to the “previous” node, because it is now at the end
                    tailPointer = current;
                }
            }
        }
コード例 #3
0
ファイル: PelletList.cs プロジェクト: sleemjm1/IN710-sleemjm1
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            Pellet pelletWalker = headPointer;

            if (pelletToDelete == headPointer)
            {
                if (pelletToDelete == tailPointer)
                {
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    headPointer = headPointer.Next;
                }
            }
            else
            {
                while (pelletWalker != null)
                {
                    if (pelletWalker.Next == pelletToDelete)
                    {
                        if (pelletToDelete == tailPointer)  //if we are going to delete last pellet in the list
                        {
                            tailPointer = pelletWalker;     //point tailpointer at previous pellet
                        }
                        else                                //we're on a normal pellet
                        {
                            pelletWalker.Next = pelletToDelete.Next;
                        }
                    }
                    pelletWalker = pelletWalker.Next;
                }
            }
        }
コード例 #4
0
ファイル: PelletList.cs プロジェクト: dec-k/IN710-keigdl1
        //==============================================================================
        // Constructor
        //==============================================================================
        public PelletList(Rectangle boundsRectangle)
        {
            //Important! Set head & tail to null at init otherwise things go boom. Big boom.
            headPointer = null;
            tailPointer = null;

            this.boundsRectangle = boundsRectangle;
        }
コード例 #5
0
ファイル: PelletList.cs プロジェクト: sleemjm1/IN710-sleemjm1
        //==============================================================================
        // Walk the list, calling the Move() method of each Pellet
        //==============================================================================
        public void Move()
        {
            Pellet pelletWalker = headPointer;

            while (pelletWalker != null)
            {
                pelletWalker.Move();
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #6
0
        //==============================================================================
        // Walk the list, calling the Move() method of each Pellet
        //==============================================================================
        public void Move()
        {
            Pellet current = headPointer;

            while (current != null)
            {
                current.Move();
                current = current.Next;
            }
        }
コード例 #7
0
        //==============================================================================
        // Walk the list, calling the Move() method of each Pellet
        //==============================================================================
        public void Move()
        {
            Pellet nodeWalker = headPointer;

            while (nodeWalker != null)
            {
                nodeWalker.Move();
                nodeWalker = nodeWalker.Next;
            }
        }
コード例 #8
0
ファイル: PelletList.cs プロジェクト: lifengdai/IN710dail3
        //==============================================================================
        // Walk the list, calling the Move() method of each Pellet
        //==============================================================================
        public void Move()
        {
            Pellet walker = headPointer;

            while (walker != null)
            {
                walker.Move();
                walker = walker.Next;
            }
        }
コード例 #9
0
ファイル: PelletList.cs プロジェクト: lifengdai/IN710dail3
        //==============================================================================
        // Walk the list. For each Pellet, call TestOutOfBounds, passing boundsRectangle.
        // For each node that is out of bounds, set its IsAlive property to false.
        //==============================================================================
        public void KillOutOfBounds()
        {
            Pellet walker = headPointer;

            while (walker != null)
            {
                walker.IsAlive = walker.TestOutOfBounds(boundsRectangle);
                bool b = walker.IsAlive;
                walker = walker.Next;
            }
        }
コード例 #10
0
        //==============================================================================
        // Walk the list, calling the Move() method of each Pellet
        //==============================================================================
        public void Move()
        {
            // Assign the pelletWalker to reference the same pellet as headPointer
            Pellet pelletWalker = headPointer;

            while (pelletWalker != null)
            {
                pelletWalker.Move();
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #11
0
        //==============================================================================
        // Walk the list, counting the number of Pellet. Return the count.
        //==============================================================================
        public int Count()
        {
            int    count   = 0;
            Pellet current = headPointer;

            while (current != null)
            {
                count++;
                current = current.Next;
            }
            return(count);
        }
コード例 #12
0
        //==============================================================================
        // Walk the list, counting the number of Pellet. Return the count.
        //==============================================================================
        public int Count()
        {
            int    count      = 0;
            Pellet nodeWalker = headPointer;

            while (nodeWalker != null)
            {
                count++;
                nodeWalker = nodeWalker.Next;
            }
            return(count);
        }
コード例 #13
0
        //==============================================================================
        // Walk the list, counting the number of Pellet. Return the count.
        //==============================================================================
        public int Count()
        {
            int    pelletCount  = 0;
            Pellet pelletWalker = headPointer;

            while (pelletWalker != null)
            {
                pelletCount++;
                pelletWalker = pelletWalker.Next;
            }
            return(pelletCount);
        }
コード例 #14
0
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     if (headPointer != null)
     {
         tailPointer.Next = newPellet;
         tailPointer = newPellet;
     }
     else{
         headPointer = newPellet;
         tailPointer = newPellet;
     }
 }
コード例 #15
0
        //==============================================================================
        // Walk the list. For each Pellet, call TestOutOfBounds, passing boundsRectangle.
        // For each node that is out of bounds, set its IsAlive property to false.
        //==============================================================================
        public void KillOutOfBounds()
        {
            Pellet current = headPointer;

            while (current != null)
            {
                if (current.TestOutOfBounds(boundsRectangle))
                {
                    current.IsAlive = false;
                }
                current = current.Next;
            }
        }
コード例 #16
0
        //==============================================================================
        // Walk the list, deleting all nodes whose IsAlive propoerty is false
        //==============================================================================
        public void DeleteNotAlive()
        {
            Pellet current = headPointer;

            while (current != null)
            {
                if (current.IsAlive == false)
                {
                    DeleteOne(current);
                }
                current = current.Next;
            }
        }
コード例 #17
0
ファイル: PelletList.cs プロジェクト: lifengdai/IN710dail3
        //==============================================================================
        // Walk the list, counting the number of Pellet. Return the count.
        //==============================================================================
        public int Count()
        {
            int    nodeCount = 0;
            Pellet walker    = headPointer;

            while (walker != null)
            {
                ++nodeCount;
                walker = walker.Next;
            }

            return(nodeCount);
        }
コード例 #18
0
ファイル: PelletList.cs プロジェクト: sleemjm1/IN710-sleemjm1
        //==============================================================================
        // Walk the list. For each Pellet, call TestOutOfBounds, passing boundsRectangle.
        // For each node that is out of bounds, set its IsAlive property to false.
        //==============================================================================
        public void KillOutOfBounds()
        {
            Pellet pelletWalker = headPointer;

            while (pelletWalker != null)
            {
                if (pelletWalker.TestOutOfBounds(boundsRectangle))
                {
                    pelletWalker.IsAlive = false;
                }
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #19
0
ファイル: PelletList.cs プロジェクト: sleemjm1/IN710-sleemjm1
        //==============================================================================
        // Walk the list, deleting all nodes whose IsAlive propoerty is false
        //==============================================================================
        public void DeleteNotAlive()
        {
            Pellet pelletWalker = headPointer;

            while (pelletWalker != null)
            {
                if (pelletWalker.IsAlive == false)
                {
                    DeleteOne(pelletWalker);
                }
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #20
0
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     if (headPointer == null)
     {
         headPointer = newPellet;
         tailPointer = newPellet;
     }
     else
     {
         tailPointer.Next = newPellet;
         tailPointer      = newPellet;
     }
 }
コード例 #21
0
        //==============================================================================
        // Walk the list. For each Pellet, call TestOutOfBounds, passing boundsRectangle.
        // For each node that is out of bounds, set its IsAlive property to false.
        //==============================================================================
        public void KillOutOfBounds()
        {
            Pellet nodeWalker = headPointer;

            while (nodeWalker != null)
            {
                if (nodeWalker.TestOutOfBounds(boundsRectangle))
                {
                    nodeWalker.IsAlive = false; //Kill out of bounds pellet
                }
                nodeWalker = nodeWalker.Next;
            }
        }
コード例 #22
0
ファイル: PelletList.cs プロジェクト: gregfield/IN710-fielgm2
        //==============================================================================
        // Walk the list, deleting all nodes whose IsAlive propoerty is false
        //==============================================================================
        public void DeleteNotAlive()
        {
            Pellet nodeWalker = headPointer;

            while (nodeWalker != null)
            {
                if (nodeWalker.IsAlive == false)
                {
                    DeleteOne(nodeWalker);
                }
                nodeWalker = nodeWalker.Next;
            }
        }
コード例 #23
0
ファイル: PelletList.cs プロジェクト: paddymoran/IN710morapd1
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     // if the list is empty, point the head and tail to the new pellet
     if (Count() == 0)
     {
         headPointer = newPellet;
         tailPointer = newPellet;
     }
     // else point the current tail's Next to the new pallet, then point the tail pointer to the new pallet
     else
     {
         tailPointer.Next = newPellet;
         tailPointer = newPellet;
     }
 }
コード例 #24
0
        //==============================================================================
        // Walk the list, calling each node's Draw method
        //==============================================================================
        public void Draw()
        {
            // Assign the pelletWalker to reference the same pellet as headPointer
            Pellet pelletWalker = headPointer;

            // Loop through the list as long as it is not null
            while (pelletWalker != null)
            {
                // Draws the pellet
                pelletWalker.Draw();

                // Save next pellet to pelletWalker
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #25
0
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     // Add to empty list
     if (headPointer == null)
     {
         // Both head and tail pointer point to the new single pellet
         headPointer = newPellet;
         tailPointer = newPellet;
     }
     else
     {
         // The newPellet will be added to the Next of tail (making a new node) and the pointer will point to that node now
         tailPointer.Next = newPellet;
         tailPointer      = newPellet;
     }
 }
コード例 #26
0
ファイル: PelletList.cs プロジェクト: acraig94/IN710craia4
        //==============================================================================
        // Add Pellet newPellet at the end of the list.
        //==============================================================================
        public void addPellet(Pellet newPellet)
        {
            if (headPointer == null)
            {
                headPointer = newPellet;
                tailPointer = newPellet;
            }
            //
            else //(tailPointer != null)
            {
                tailPointer.Next = newPellet;
                tailPointer = newPellet;
            }

            //throw new NotImplementedException();
        }
コード例 #27
0
        //==============================================================================
        // Walk the list, counting the number of Pellet. Return the count.
        //==============================================================================
        public int Count()
        {
            // Create count to keep track of how many pellets there are
            // Assign the pelletWalker to reference the same pellet as headPointer
            int    count        = 0;
            Pellet pelletWalker = headPointer;

            // if the pelletWalker has not reached the end of the list then increment the count and set the
            // pelletWalker to point to the next pellet in the list
            while (pelletWalker != null)
            {
                count++;
                pelletWalker = pelletWalker.Next;
            }

            return(count);
        }
コード例 #28
0
        //==============================================================================
        // Walk the list. For each Pellet, call TestOutOfBounds, passing boundsRectangle.
        // For each node that is out of bounds, set its IsAlive property to false.
        //==============================================================================
        public void KillOutOfBounds()
        {
            // Assign the pelletWalker to reference the same pellet as headPointer
            Pellet pelletWalker = headPointer;

            while (pelletWalker != null)
            {
                // When pelletWalker goes out of bound, the bool alive property is set to false
                if (pelletWalker.TestOutOfBounds(boundsRectangle) == true)
                {
                    pelletWalker.IsAlive = false;
                }

                // Set next pellet to be the pelletWalker
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #29
0
ファイル: PelletList.cs プロジェクト: doglitbug/IN710dickaj1
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     //Check if the list is empty
     if (headPointer == null)
     {
         //Set head and tail to point to the new pellet
         headPointer = newPellet;
         tailPointer = newPellet;
     }
     else
     {
         //Get last item and point its next to the new pellet
         tailPointer.Next = newPellet;
         //Point tailPointer to the new pellet
         tailPointer = newPellet;
     }
 }
コード例 #30
0
ファイル: PelletList.cs プロジェクト: dec-k/IN710-keigdl1
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     //First, check if we are attempting to add to an empty list
     if (headPointer == null)
     {
         //Then we assign the new pellet as both head & tail - now we have a list
         //which is 1 pellet long.
         headPointer = newPellet;
         tailPointer = newPellet;
     }
     else
     {
         //If the list isn't empty, append the new pellet to the end of the list
         tailPointer.Next = newPellet;
         tailPointer = newPellet;
     }
 }
コード例 #31
0
ファイル: Pellet.cs プロジェクト: sleemjm1/IN710-sleemjm1
        public Pellet(int xPos, int yPos, Graphics canvas, Random rGen)
        {
            // Grab input args
            this.xPos   = xPos;
            this.yPos   = yPos;
            this.canvas = canvas;
            this.rGen   = rGen;

            // Set default values
            xVel    = 0;                            // Change this if you want diagonal motion
            yVel    = rGen.Next(MAX_SPEED) + MIN_SPEED;
            yVel   *= -1;                           // Moving up the screen
            IsAlive = true;                         // Start live so not culled from list

            brush = genRandomColourBrush();

            Next = null;                            // ESSENTIAL for being a list node
        }
コード例 #32
0
        //==============================================================================
        // Walk the list, deleting all nodes whose IsAlive propoerty is false
        //==============================================================================
        public void DeleteNotAlive()
        {
            // Assign the pelletWalker to reference the same pellet as headPointer
            Pellet pelletWalker = headPointer;

            // Loop through the list as long as it is not null
            while (pelletWalker != null)
            {
                // Check if the state current pellet and if it is false then it will run the DeleteOne method
                if (pelletWalker.IsAlive == false)
                {
                    DeleteOne(pelletWalker);
                }

                // Save next pellet to pelletWalker
                pelletWalker = pelletWalker.Next;
            }
        }
コード例 #33
0
ファイル: PelletList.cs プロジェクト: hornoo/IN710hornerb1
        //==============================================================================
        // Add Pellet newPellet at the end of the list.
        //==============================================================================
        public void addPellet(Pellet newPellet)
        {
            //If head pointer == null there are no nodes in the list, set both the head and tail to point to the added node(by defaul it's next should already point to null)
            if(headPointer == null)
            {

                headPointer = newPellet;
                tailPointer = newPellet;

            }else //else  set the tail pointer.next to = the new pellet and the tail pointer to = the new pellet, this means the tail it pointing at the new pellet object and object
                //which is still the same thing is the new pellet and as it is new pellet its .next points at null.(as it was set to null when instantiated) - I dont understand this bit.
            {
                tailPointer.Next = newPellet;
                tailPointer = newPellet;
            }

            //throw new NotImplementedException();
        }
コード例 #34
0
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            // Assign the pelletWalker to reference the same pellet as headPointer
            Pellet pelletWalker = headPointer;

            // Checks if the pelletWalker and pelletToDelete points to the same pellet
            if (headPointer == pelletToDelete)
            {
                // Check if the next one on the list is null
                // If it is then there is only one Pellet left in the List and headPointer and tailPointer will be set to null
                if (pelletWalker.Next == null)
                {
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    // Set the second pellet in List to be the headPointer
                    headPointer = pelletWalker.Next;
                }
            }
            else
            {
                // Will loop through if pelletWalker.Next does not equal to pelletToDelete
                // and have pelletWalker traverse along the List until it points to the pelletToDelete
                while (pelletWalker.Next != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }

                // When out of the loop, the pelletWalker.Next = pelletToDelete
                // the next pellet of the pelletToDelete will be saved into the next pellet of pelletWalker (which is pelletToDelete)
                // so the pellet next to pelletToDelete will now take the place of pelletToDelete
                pelletWalker.Next = pelletToDelete.Next;

                // Checks if the next pellet is at the end of the List
                // if it is then set current pellet (pelletWalker) to tailPointer
                if (pelletWalker.Next == null)
                {
                    tailPointer = pelletWalker;
                }
            }
        }
コード例 #35
0
ファイル: PelletList.cs プロジェクト: gregfield/IN710-fielgm2
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //if head is pellet to delete
            if (pelletToDelete == headPointer)
            {
                //if it only pellet
                if (headPointer == tailPointer)
                {
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    headPointer = pelletToDelete.Next;
                }
            }
            else
            {
                Pellet nodeWalker = headPointer;

                while (nodeWalker.Next != pelletToDelete)
                {
                    nodeWalker = nodeWalker.Next;
                }
                //if pellet to delete is tail pallet make tail equal nodewalker
                if (tailPointer == pelletToDelete)
                {
                    if (nodeWalker.Next == pelletToDelete)
                    {
                        tailPointer = nodeWalker;
                    }
                }
                //if next pellet is pallet to delete make one after it next pallet
                if (nodeWalker.Next == pelletToDelete)
                {
                    nodeWalker.Next = pelletToDelete.Next;
                }
            }
        }
コード例 #36
0
ファイル: Form1.cs プロジェクト: sleemjm1/IN710-sleemjm1
        //==============================================================================
        // KeyDown handler
        // Moves chicken in direction of arrow key
        // Fires a pellet on spacebar
        //==============================================================================
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Left)
            {
                pbxChicken.Left -= STEP_SIZE;
            }

            if (e.KeyData == Keys.Right)
            {
                pbxChicken.Left += STEP_SIZE;
            }

            if (e.KeyData == Keys.Space)
            {
                //Generate a new Pellet at chicken's location
                Pellet newPellet = new Pellet(pbxChicken.Left + (pbxChicken.Width / 2),
                                              pbxChicken.Top - PELLET_DIAMETER,
                                              mainCanvas,
                                              rGen);
                mainPelletList.addPellet(newPellet);
            }
        }
コード例 #37
0
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //if theres only one pellet
            if (headPointer == tailPointer)
            {
                headPointer = null;
                tailPointer = null;
            }

            //if deleting last pellet
            else if (pelletToDelete == tailPointer)
            {
                Pellet pelletWalker = headPointer;
                while (pelletWalker.Next != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }
                tailPointer = pelletWalker;
            }
            // if deleting frist pellet
            else if (headPointer == pelletToDelete)
            {
                headPointer = pelletToDelete.Next;
            }

            //if deleting pellet in linked list longer than 2
            else
            {
                Pellet pelletWalker = headPointer;
                while (pelletWalker != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }
                pelletWalker = pelletToDelete.Next;
            }
        }
コード例 #38
0
ファイル: PelletList.cs プロジェクト: lifengdai/IN710dail3
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            Pellet walker = headPointer;

            if (headPointer == pelletToDelete)
            {
                if (Count() == 1)
                {
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    headPointer = headPointer.Next;
                }
            }
            else
            {
                if (tailPointer == pelletToDelete)
                {
                    while (walker.Next != pelletToDelete)
                    {
                        walker = walker.Next;
                    }
                    tailPointer = walker;
                }
                else
                {
                    while (walker.Next != pelletToDelete)
                    {
                        walker = walker.Next;
                    }
                    walker.Next = pelletToDelete.Next;
                }
            }
        }
コード例 #39
0
ファイル: PelletList.cs プロジェクト: paddymoran/IN710morapd1
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            // if pellet to delete is the first in the list
            if (pelletToDelete == headPointer)
            {
                if (pelletToDelete == tailPointer)
                {
                    // pelletToDelete is the only item in the list
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    // pelletToDelete is first, but not the only item in the list
                    headPointer = pelletToDelete.Next;
                }
            }
            // if pelletToDelete is the last item in the list
            else if (pelletToDelete == tailPointer)
            {
                Pellet nodeWalker = headPointer;

                while (nodeWalker != null)
                {
                    if (nodeWalker.Next == tailPointer)
                    {
                        nodeWalker.Next = null;
                        tailPointer = nodeWalker;
                    }

                    nodeWalker = nodeWalker.Next;
                }
            }
            // pelletToDelete is in the list, but not the first or last
            else
            {
                Pellet nodeWalker = headPointer;

                while (nodeWalker != null)
                {
                    if (nodeWalker.Next == pelletToDelete)
                    {
                        // set the current node walker's (the node before the one to delete) next to the the node after the node to be deleted
                        nodeWalker.Next = pelletToDelete.Next;

                        // We found it, so let's set this to null to exit the loop
                        nodeWalker = null;
                    }
                    else
                    {
                        // set nodeWalker to the next node
                        nodeWalker = nodeWalker.Next;
                    }
                }
            }
        }
コード例 #40
0
ファイル: PelletList.cs プロジェクト: gregfield/IN710-fielgm2
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //if head is pellet to delete
            if (pelletToDelete == headPointer)
            {
                //if it only pellet
                if (headPointer == tailPointer )
                {
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    headPointer = pelletToDelete.Next;
                }
            }
            else
            {
                Pellet nodeWalker = headPointer;

                while (nodeWalker.Next != pelletToDelete)
                    nodeWalker = nodeWalker.Next;
                    //if pellet to delete is tail pallet make tail equal nodewalker
                    if (tailPointer == pelletToDelete)
                    {
                        if (nodeWalker.Next == pelletToDelete)
                            tailPointer = nodeWalker;

                    }
                    //if next pellet is pallet to delete make one after it next pallet
                    if (nodeWalker.Next == pelletToDelete)
                    {
                        nodeWalker.Next = pelletToDelete.Next;
                    }

            }
        }
コード例 #41
0
ファイル: PelletList.cs プロジェクト: paddymoran/IN710morapd1
 //==============================================================================
 // Add Pellet newPellet at the end of the list.
 //==============================================================================
 public void addPellet(Pellet newPellet)
 {
     throw new NotImplementedException();
 }
コード例 #42
0
ファイル: PelletList.cs プロジェクト: paddymoran/IN710morapd1
 //==============================================================================
 // Delete the argument Pellet pelletToDelete from the list.
 // Be careful to maintain the integrity of the list, including
 // headPointer and tailPointer.
 //==============================================================================
 public void DeleteOne(Pellet pelletToDelete)
 {
     throw new NotImplementedException();
 }
コード例 #43
0
 //==============================================================================
 // Delete the argument Pellet pelletToDelete from the list.
 // Be careful to maintain the integrity of the list, including
 // headPointer and tailPointer.
 //==============================================================================
 public void DeleteOne(Pellet pelletToDelete)
 {
     pelletToDelete.IsAlive = false;
 }
コード例 #44
0
ファイル: PelletList.cs プロジェクト: doglitbug/IN710dickaj1
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //Check if this is the first node in the list
            if (headPointer == pelletToDelete)
            {
                //Check if it is the only node in the list
                if (tailPointer == pelletToDelete)
                {
                    headPointer = tailPointer = null;
                }
                else
                    //More than one pellet in the list
                {
                    //Move the headpointer to the next pellet
                    headPointer = pelletToDelete.Next;
                }
            }
            else
                //Not the first pellet and more than one in the list
            {
                //Prepare to walk the list
                Pellet pelletWalker = headPointer;

                //Find the pellet before pelletToDelete
                while (pelletWalker.Next != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }
                //Found previous pellet, swoop around
                pelletWalker.Next = pelletToDelete.Next;

                //Check this wasn't the last node in the list
                //Changed this from "tailPointer == null" incase it was only working due to
                //efficent garbage collection
                if (pelletWalker.Next==null)
                {
                    tailPointer = pelletWalker;
                }
            }
        }
コード例 #45
0
ファイル: PelletList.cs プロジェクト: hornoo/IN710hornerb1
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            // the node to delete is the same as the head pointer check how many nodes in the list, if it is the only node set the head and tail to both be null, in c# the garbage collector will get rid of it, thi smay not happen in other languages.
            if(pelletToDelete == headPointer)
            {
                if(Count() == 1)
                {
                    headPointer = null;
                    tailPointer = null;
                }
                else // else set the head pointer to point at the node to deletes.Next which heand the deah is now point at the first node and the previous one will get collected by garbage collection
                {
                    headPointer = pelletToDelete.Next;
                }

            }
            else // now if its no the the first pellet in the list, walk the list from the second node in the link list
            {
                // create a nodewalker that is the head pointer
                Pellet nodewalker = headPointer;

                while(nodewalker.Next != null)
                {
                    // set the node walkerbo net the second node int he lin list by setting it as its.next, this is usually done after a operation on the list but as we already know that the
                    //first not is not the one to delete we start here.
                    nodewalker = nodewalker.Next;

                    //if the node walker.next is the node we want to delete, we know that the node is the link before the one we want to delete.
                    if(nodewalker.Next == pelletToDelete)
                    {
                        //we need to check if the node we want to delete is the last link in the list(or the tail, if we lost the tail the list loses intgerity)
                        // we check by seeing if the node walkers.next is the tail pointer, if it is set the tailpointer to node\point at the node and set the node.next to = null(so that it doesnt point to any other node now, which was the one we ewanted to delete) garabage collection should nowremove the pnotde we want to delete.
                        if(nodewalker.Next == tailPointer)
                        {

                        tailPointer = nodewalker;
                        nodewalker.Next = null;
                        }
                        else // we now know the node we want to delete is not the tail also, so we can just set the node walkers.next to be the node we want to deletes.next meaning there is now no refference to the node we want to delete in the linklist
                        {

                            nodewalker.Next = pelletToDelete.Next;
                        }

                    }

                       //while loop gets to the end of list list and breaks out when the node walker is set to null.
                }

            }
            //throw new NotImplementedException();
        }
コード例 #46
0
ファイル: PelletList.cs プロジェクト: acraig94/IN710craia4
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            Pellet pelletWalker = headPointer;
            // if first pellet isnt the one to delete
            if (pelletWalker != pelletToDelete)
            {
                while (pelletWalker.Next != pelletToDelete)
                {
                    pelletWalker = pelletWalker.Next;
                }
                // if the pellet to delete is the last one
                if (pelletWalker.Next == tailPointer)
                {
                    tailPointer = pelletWalker;
                }
                // pellet anywhere in between
                else
                {
                    pelletWalker.Next = pelletToDelete.Next;
                }
            }

            else
            {
                // if the pellet to delete is the only pellet in the list
                if (headPointer == tailPointer)
                {
                    headPointer = null;
                    tailPointer = null;
                }
                // if pellet is the first in list
                else
                {
                    headPointer = pelletWalker.Next;
                }
            }

            //throw new NotImplementedException();
        }
コード例 #47
0
ファイル: PelletList.cs プロジェクト: watset1/IN710watset1
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            Pellet nodeWalker = headPointer;

            //If deleting the only pellet in the list
            if (headPointer == tailPointer)
            {
                headPointer = null;
                tailPointer = null;
            }
            else
            {
                //If deleting first pellet in list when there are more than one in list
                if (pelletToDelete == headPointer && pelletToDelete.Next != null)
                {
                    headPointer = pelletToDelete.Next;
                }

                else
                {
                    while (nodeWalker.Next != pelletToDelete)
                    {
                        nodeWalker = nodeWalker.Next;
                    }

                    nodeWalker.Next = pelletToDelete.Next;
                    //If deleting last pellet in list
                    if (pelletToDelete.Next == null)
                    {
                        tailPointer = nodeWalker;
                    }
                }
            }
        }
コード例 #48
0
ファイル: PelletList.cs プロジェクト: lifengdai/IN710dail3
 //==============================================================================
 // Delete the argument Pellet pelletToDelete from the list.
 // Be careful to maintain the integrity of the list, including
 // headPointer and tailPointer.
 //==============================================================================
 public void DeleteOne(Pellet pelletToDelete)
 {
     Pellet walker = headPointer;
     if (headPointer == pelletToDelete)
     {
         if (Count() == 1)
         {
             headPointer = null;
             tailPointer = null;
         }
         else
         {
             headPointer = headPointer.Next;
         }
     }
     else
     {
         if(tailPointer == pelletToDelete)
         {
             while (walker.Next != pelletToDelete)
             {
                 walker = walker.Next;
             }
             tailPointer = walker;
         }
         else
         {
             while (walker.Next != pelletToDelete)
             {
                 walker = walker.Next;
             }
             walker.Next = pelletToDelete.Next;
         }
     }
 }
コード例 #49
0
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            Pellet nodeWalker = headPointer;
            if (pelletToDelete == headPointer)
            {
                if (pelletToDelete != tailPointer)
                {
                    headPointer = pelletToDelete.Next;
                }
                else
                {
                    headPointer = null;
                    tailPointer = null;
                }
            }
            else
            {
                    while (nodeWalker != null)
                    {
                        if (nodeWalker.Next == tailPointer)
                        {
                            tailPointer = nodeWalker;
                        }

                        if (nodeWalker.Next == pelletToDelete)
                        {
                            nodeWalker.Next = pelletToDelete.Next;
                        }
                        nodeWalker = nodeWalker.Next;
                    }
            }

            //My first attempt that failed
            //Pellet nodeWalker = headPointer;
            //Pellet previousPellet = null;
            //if ((pelletToDelete != headPointer) && (pelletToDelete != tailPointer))
            //{
            //    if (pelletToDelete == nodeWalker)
            //    {
            //        headPointer = pelletToDelete.Next;
            //    }
            //    else
            //    {
            //        while (nodeWalker.Next != pelletToDelete)
            //        {
            //            previousPellet = nodeWalker;
            //            nodeWalker = nodeWalker.Next;

            //            if (nodeWalker.Next == pelletToDelete)
            //            {
            //                nodeWalker.Next = pelletToDelete.Next;

            //                if (pelletToDelete == tailPointer)
            //                {
            //                    tailPointer = previousPellet;
            //                }
            //            }

            //        }
            //    }
            //}
            //else
            //{
            //    headPointer = null;
            //    tailPointer = null;
            //}
        }
コード例 #50
0
        //==============================================================================
        // Walk the list, deleting all nodes whose IsAlive propoerty is false
        //==============================================================================
        public void DeleteNotAlive()
        {
            Pellet nodeWalker = headPointer;

            while (nodeWalker != null)
            {
                if (nodeWalker.IsAlive == false)
                {

                    //if the node to delete is the only node
                    if(nodeWalker == headPointer && nodeWalker == tailPointer)
                    {
                        //set both head and tail to null
                        headPointer = null;
                        tailPointer = null;
                    }

                    // if the node to delete is the head
                    else if (nodeWalker == headPointer)
                    {
                        //set head to the next node in the list
                        headPointer = nodeWalker.Next;
                    }

                    //if the node th be deleted is the last node
                    else if (nodeWalker == tailPointer)
                    {
                        Pellet nw = headPointer;

                        //find the node before the tail node and moke it the new tail
                        while (nw != null)
                        {
                            if (nw.Next == nodeWalker)
                            {
                                tailPointer = nw;
                            }

                            nw = nw.Next;
                        }
                    }

                    //if the node to be deleted is in the middle of the list
                    else
                    {
                        Pellet nw = headPointer;

                        //find the node before the node to be deleted and set it's next to the node after the node to be deleted
                        while (nw != null)
                        {
                            if (nw.Next == nodeWalker)
                            {
                                nw.Next = nodeWalker.Next;
                            }

                            nw = nw.Next;
                        }
                    }
                }

                nodeWalker = nodeWalker.Next;
            }
        }
コード例 #51
0
ファイル: PelletList.cs プロジェクト: dec-k/IN710-keigdl1
        //==============================================================================
        // Delete the argument Pellet pelletToDelete from the list.
        // Be careful to maintain the integrity of the list, including
        // headPointer and tailPointer.
        //==============================================================================
        public void DeleteOne(Pellet pelletToDelete)
        {
            //Create a nodewalker as usual
            Pellet listWalker = headPointer;

            //Case for when the current listwalker is a headpointer.
            if (pelletToDelete == headPointer) //Goddamnit. Spent three hours on this line. Used to be listWalker == headpointer.
            {
                //When the pellet we want to delete is the only pellet.
                if (listWalker.Next == null)
                {
                    //Kill it.
                    headPointer = null;
                    tailPointer = null;
                }
                else
                {
                    //Otherwise, continue walking through the list.
                    headPointer = listWalker.Next;
                }
            }
            else
            {
                //While loop to delete things sitting in the lists interior (swoop)
                while (listWalker.Next != pelletToDelete)
                {
                    listWalker = listWalker.Next; //Not found, step to the next pellet.
                }

                listWalker.Next = pelletToDelete.Next;
                if (listWalker.Next == null)
                {
                    tailPointer = listWalker;
                }
            }
        }