From the course: Advanced Java Programming
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Implementing a queue with a linked list - Java Tutorial
From the course: Advanced Java Programming
Implementing a queue with a linked list
- [Instructor] A queue is first in first out status structure, queues are useful if you are controlling access to shared resources. For example CPU scheduling or doing something like simulating planes waiting for landing instructions. In this example, I have two classes. One called customer and one called store. The customer class has two fields. One is a sting called name, and the name must be passed into the constructor when a new customer is created. The second is a bullion called has been served. This is set to false by default when a customer is created. There is a method in this class called serve, which sets has been served to true and prints a message to say that they have been served. I have also overridden the string method in this class, and set it to return the name field. This is so that when I add customers to a queue and then print the queue it will show me the customers name rather than the objects reference. In the store class I have a main method. Inside the main…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.