隊列(JAVA實現(xiàn))“>數(shù)據(jù)結(jié)構(gòu)->隊列(JAVA實現(xiàn))
/**
* 判斷是否存在
*/
@Override
public boolean contains(Object object) {
LinkNode linkNodeNowTemp = headNode;
for (int i = 0; i < nodeSize; i++) {
if (object == linkNodeNowTemp.date) {
return true;
}
linkNodeNowTemp = linkNodeNowTemp.nextLinkNode;
}
return false;
}
/**
* 隊列是否為空
*/
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return nodeSize == 0;
}
@Override
public int size() {
// TODO Auto-generated method stub
return nodeSize;
}
/**
* 根據(jù)索引號查找節(jié)點
*
* @param index
* @return
*/
public LinkNode findLinkNodeByIndex(int index) {
LinkNode linkNodeNowTemp = headNode;
for (int i = 0; i < nodeSize; i++) {
if (i == index) {
return linkNodeNowTemp;
}
linkNodeNowTemp = linkNodeNowTemp.nextLinkNode;
}
return null;
}
@Override
public String toString() {
StringBuffer str = new StringBuffer("[");
LinkNode linkNode = null;
for (int i = 0; i < nodeSize; i++) {
linkNode = findLinkNodeByIndex(i);
str.append("[" + linkNode.date + "],");
}
if (nodeSize > 0) {
return str.substring(0, str.lastIndexOf(",")) + "]";
}
return str.append("]").toString();
}
}
評論