package shark.zd.矢量;
import java.io.PrintWriter; import java.util.Vector;
public class operateVector { private Vector para; //创建一个二维的矢量数组
public Vector buildVector(){ Vector vTemps = new Vector(); for(int i=0;i<4;i++){ Vector vTemp = new Vector(); for(int j=0;j<4;j++){ vTemp.addElement("Vector("+i+")("+j+")"); } vTemps.addElement(vTemp); } return vTemps; } public Vector insert(Vector vTemp,int iTemp,Object oTemp){ if (iTemp>vTemp.size()) { print("数据溢出"); return null; } else { vTemp.insertElementAt(oTemp, iTemp); } return vTemp; } public Vector delete(Vector vTemp,int iTemp){ if(iTemp>vTemp.size()){ print("数据越界"); return null; } else{ vTemp.removeElementAt(iTemp); } return vTemp; } public Vector updata(Vector vTemp,int iTemp,Object oTemp){ if (iTemp>vTemp.size()) { print("数据越界"); return null; } else { vTemp.setElementAt(oTemp, iTemp);
} return vTemp; } public void print(Object oTemp) { // TODO Auto-generated method stub
System.out.println(oTemp); } public void print(Vector vPara){ for(int i=0;i<vPara.size();i++){ System.out.println(vPara.elementAt(i)); } } public void print(String sTemp,Vector vTemp) { // TODO Auto-generated method stub
System.out.println(sTemp+"数据:"); this.print(vTemp); } public static void main(String[] args){ operateVector ov = new operateVector(); Vector vTemp = ov.buildVector(); ov.print("vTemp0",vTemp); Vector Iinsert = ov.insert(vTemp, 2, "添加的数据"); ov.print("Iinsert",Iinsert); Vector UP = ov.updata(vTemp, 2, "修改的数据"); ov.print("UP",UP ); Vector RE = ov.delete(vTemp, 3); ov.print("RE", RE); } }
|