เมนูนำทาง
วีลิสต์ ตัวอย่างการเขียนรหัส(code) เขียนด้วยภาษาจาวา (Java) ซึ่งได้ดัดแปลงให้การนับจำนวนข้อมูลใช้เวลา O(1) และเพิ่มเมธ็อด (method) เพิ่มเติมเข้าไป
public class Vlist { private static class Block { Object[] element; Block base; int size; int lastUsed; int offSet; public Block(int size, Block base) { this.size = size; this.base = base; if (base == null) this.offSet = 0; else this.offSet = base.offSet + base.size; this.lastUsed = 0; element = new Object[size]; } } Block header; final int r = 2; public Vlist() { header = new Block(0, null); header.base = new Block(2, null); } public void add(Object e) { if (header.base.element[header.base.lastUsed] != null && header.base.lastUsed + 1 == header.base.size) { header.base = new Block(header.base.size * 2, header.base); } if (header.base.element[header.base.lastUsed] == null) { header.base.element[header.base.lastUsed] = e; return; } header.base.element[++header.base.lastUsed] = e; } public int size() { return header.base.offSet + header.base.lastUsed + 1; } public Object get(int index) { Block current = header.base; while (index - current.offSet < 0) { current = current.base; } return current.element[index - current.offSet]; } public void removeLast() { if (header.base == null) return; header.base.lastUsed--; if (header.base.lastUsed < 0) { header.base = header.base.base; } } public void set(int index, Object e) { Block current = header.base; while (index - current.offSet < 0) { current = current.base; } current.element[index - current.offSet] = e; } public int indexOf(Object e) { Block current = header.base; int index = size() - 1; while (current != null) { if (current.element[index - current.offSet].equals(e)) return index; index--; if (index < current.offSet) current = current.base; } return -1; }}
เมนูนำทาง
วีลิสต์ ตัวอย่างการเขียนใกล้เคียง
วีลิสต์แหล่งที่มา
WikiPedia: วีลิสต์ http://infoscience.epfl.ch/record/64410/files/tech... http://www.codeproject.com/KB/collections/vlist.as... http://citeseer.ist.psu.edu/bagwell02fast.html http://www.ootl.org/doc/vlist.html