public class NewStack<Item> implements Iterable<Item>{
private int N=0;
private Note first;
private class Note{
Item item;
Note nextNote;
}
public boolean isEmpty(){return first==null;};
public int size(){return N;};
public void push(Item item){
Note old = first;
first = new Note();
first.nextNote = old;
first.item = item;
N++;
}
public Item pop(){
Item item = first.item;
first = first.nextNote;
N--;
return item;
}
@Override
public Iterator<Item> iterator() {
return null;
}
private class MyIterator<Item> implements Iterator<Item>{
private int i= N;
@Override
public boolean hasNext() {
return i>0;
}
@Override
public Item next() {
return (Item)first.nextNote.item;
}
@Override
public void remove() {
}
}
}
数据结构(二)链表(一)单链表
最新推荐文章于 2024-07-11 15:29:35 发布