How would you design a queue abstract data type for float elements in C (or any preferred language), with operations for enqueue, dequeue, and empty? The dequeue operation should remove the element and returns its value.
Using Java, I came up with a quick and dirty solution as follows:
public class QueueOps {
private ArrayList<Float> queueReference;
public QueueOps(){
queueReference = new ArrayList<Float>();
}
public void enqueue(float number){
queueReference.add(number);
}
public float dequeue(){
float number = queueReference.get(0);
queueReference.remove(0);
queueReference.trimToSize();
return number;
}
public void empty(){
queueReference.clear();
}
}