CPT 307 Week 5 Interactive Assignment

In this post, I used the queue function. In this Java program I used the add (), element(), offer(), peek(), and poll() methods for the queue function. Here I set up a queue that lists different parts of a car. The queue function is used to remove elements from the beginning of the queue and insert elements at the end of the queue. This is the First in First Out method. The poll function job is to take the first element of the queue and remove it. One thing to note is that in this case, if the container is empty, a null will be presented and not an exception. The remove function deletes the head of the queue In writing this program, I needed to be able to add elements to the queue, and I did this by using the add function. This allows me to add specific items to the list I am building Using the peek stack will retain the first element it doesn’t retrieve or remove the element. The Offer method can insert elements into the queue with no issues. Many times, this is used in place of the add method because it doesn't have the same capacity restrictions as the add function does. The element operation is very much like the peek operation. One main difference is that if a queue is empty, the element function will throw out an exception, whereas a peek doesn't give an exception but a null. All of these operations are used are part of the queue interface in Java util package. This particular collection allows a place for information to be stored that is in the midst of being processed. It follows the FIFO Law. Works Cited Java Stack Class Tutorial with Examples. (n.d.). Retrieved from Callicoder: https://www.callicoder.com/java-stack/ Mahrsee, R. (n.d.). Queue Interface In Java. Retrieved from Geeks for geeks: https://www.geeksforgeeks.org/queue-interface-java/ Oracle. (n.d.). Retrieved from Documentation: https://docs.oracle.com/en/

Comments

Popular posts from this blog

Network Security

About Computers