About Vector Optimization, Homemade StringVector

zhaozj2021-02-17  50

Public class stringvector {

Private static final int default_size = 3; private string [] data; private int count; public stringVector () {

This (default_size);} public stringvector (int initialsize) {

Data = new string [initialsize];} public void add (string str) {

IF (Str == Null) Return; EnSureCapacity (Count 1); Data [Count ] = Str;} Private Void EnSureCapacity (int minCapacity) {

INT Oldcapacity = data.length; if (mincapacity> oldcapacity) {

String OldData [] = data; int newcapacity = oldcapacity * 2; data = new string [newcapacity]; System.Arraycopy (OldData, 0, DATA, 0, Count);}} PUBLIC VOID REMOVE (String Str) {

IF (str == null) return; for (int i = 0; i

IF (Data [I] .Equals (str)) {

System.ArrayCopy (Data, I 1, Data, I, Count-1); Data [- count] = null; return;}}} public final string get (int index) {

IF (Index <0) Return Null; Else If (INDEX> Count) Return Null; Else Return Data [Index];

Return count;}}

转载请注明原文地址:https://www.9cbs.com/read-30395.html

New Post(0)