コード例 #1
0
        private void btnPop_Click(object sender, EventArgs e)
        {
            CDNode removeNode = JBSP1.pop();

            if (removeNode != null)
            {
                lblOutput.Text = " Removed " + removeNode.Name;
            }
            else
            {
                lblOutput.Text = "No CD's on Spindle to remove";
            }
        }
コード例 #2
0
        private void btnPeek_Click(object sender, EventArgs e)
        {
            CDNode peekNode = JBSP1.peek();

            if (peekNode != null)
            {
                lblOutput.Text = peekNode.Name + " is at the top of the spindle";
            }
            else
            {
                lblOutput.Text = "Peek not possible, no CD's on the Spindle";
            }
        }
コード例 #3
0
ファイル: Spindle.cs プロジェクト: conorlyness/JukeBox
        }//peek

        public CDNode pop()
        {
            if (isEmpty())
            {
                return(null);
            }
            else
            {
                CDNode removed = top; //creating a reference called removed
                top = removed.Prev;   //top should now be removed previous
                size--;
                return(removed);
            }//pop
        }
コード例 #4
0
ファイル: Spindle.cs プロジェクト: conorlyness/JukeBox
        }//isEmpty

        public Boolean push(CDNode newNode)
        {
            if (size >= capacity)
            {
                return(false);
            }
            else
            {
                newNode.Prev = top;
                top          = newNode;
                size++;
                return(true);
            }
        }//push
コード例 #5
0
ファイル: Spindle.cs プロジェクト: conorlyness/JukeBox
        }//push

        public string list()
        {
            if (isEmpty())
            {
                return("Spindle is empty\n");
            }
            string output  = "Contents of Stack\nCD's: " + size + "\n";
            CDNode current = top;

            while (current != null)
            {
                output += current.Name + " By " + current.Artist + "   || No. of tracks: " + current.getTracks() + "   || runtime in mins: " + current.getDuration() + "\n";
                current = current.Prev;
            }



            return(output);
        }//list
コード例 #6
0
ファイル: Spindle.cs プロジェクト: conorlyness/JukeBox
        public bool contains(string find)
        {
            if (isEmpty())
            {
                return(false);
            }

            CDNode current = top;

            while (current != null)
            {
                if (find == current.Name)
                {
                    current.getTracks();
                    current.getDuration();
                    return(true);
                }

                current = current.Prev;
            }
            return(false);
        }//contains
コード例 #7
0
        private void btnPush_Click(object sender, EventArgs e)
        {
            CDNode newCD = new CDNode();

            if (txtName.Text == "" || txtArtist.Text == "" || txtTracks.Text == "" || txtDuration.Text == "")
            {
                lblOutput.Text = "All fields need to be filled before a new CD can be added";
                return;
            }


            newCD.Name   = txtName.Text;
            newCD.Artist = txtArtist.Text;


            if (JBSP1.push(newCD))
            {
                lblOutput.Text = "CD was sucesfully added";
            }
            else
            {
                lblOutput.Text = "CD could not be added, spindle is full";
            }

            try
            {
                newCD.setTracks(Convert.ToInt32(txtTracks.Text));
                newCD.setDuration(Convert.ToInt32(txtDuration.Text));
            }
            catch (FormatException fex)
            {
                lblOutput.Text = "Error Occured, Tracks and Duration need to be a number!";
                string err = "\n" + fex.Message + DateTime.Now.ToString();
                File.AppendAllText(@"..\..\ErrorLog.txt", "\n" + err);
            }
        }
コード例 #8
0
        private void btnRemoveCD_Click(object sender, EventArgs e)
        {
            try
            {
                int toBeRemoved = (Convert.ToInt32(txtRemove.Text));
                for (int i = 0; i < toBeRemoved - 1; i++)
                {
                    CDNode nextSpindle = JBSP1.pop();
                    JBSP2.push(nextSpindle);
                }

                JBSP1.pop();
                lblOutput.Text = "The CD at position:" + txtRemove.Text + " was Succesfully removed, view the spindle again to view the changes!";
            }
            catch (FormatException fx)
            {
                lblOutput.Text = "Error Occured, Enter a number which indicates the position of the CD you wish to remove";
                string err = "\n" + fx.Message + DateTime.Now.ToString();
                File.AppendAllText(@"..\..\ErrorLog.txt", "\n" + err);
            }


            catch (NullReferenceException nrx)
            {
                lblOutput.Text = "Error, enter a position which is possible to remove";
                string err = "\n" + nrx.Message + DateTime.Now.ToString();
                File.AppendAllText(@"..\..\ErrorLog.txt", "\n" + err);
            }


            while (JBSP2.peek() != null)
            {
                CDNode nextSpindle = JBSP2.pop();
                JBSP1.push(nextSpindle);
            }
        }
コード例 #9
0
ファイル: Spindle.cs プロジェクト: conorlyness/JukeBox
 public Spindle()
 {
     top      = null;
     size     = 0;
     capacity = 10;
 }