I had wrote my code for queue ADT but it is not generic. I don't know how to convert my code to generic ADT. Anyone can help me figure out how to change my code in order to make it become generic ADT
public class DeckQueue implements DeckInterface {
private static final int ARRAY_SIZE = 10;
private String[] cardArray = new String[ARRAY_SIZE];
public void enqueue(String newEntry) {
for (int i = 0; i <= cardArray.length; i++) {
if (cardArray[i] == null) {
cardArray[i] = newEntry;
break;
}
}
}
public String dequeue() {
// get first element from array
String front = null;
if (!isEmpty()) {
front = cardArray[0];
// shift remaining array items forward one position
for (int i = 0; i < cardArray.length - 1; ++i) {
cardArray[i] = cardArray[i + 1];
}
//set last to null
cardArray[cardArray.length - 1] = null;
} else {
System.out.println("Card is empty");
}
return front;
}
public boolean isEmpty() {
return 0 == cardArray.length;
}
public void clear() {
this.cardArray = new String[ARRAY_SIZE];
}
@Override
public String toString() {
for (int i = 0; i <= cardArray.length - 1; i++) {
System.out.println(i + "=" + cardArray[i]);
}
return null;
}
}