1 public class Vector_t {
6 /* =============================================================================
8 * -- Returns null if failed
9 * =============================================================================
11 public Vector_t(int initCapacity) {
12 int capacity = Math.imax(initCapacity, 1);
14 this.capacity = capacity;
15 this.elements = new Object[capacity];
18 /* =============================================================================
20 * =============================================================================
28 /* =============================================================================
30 * -- Returns null if failed
31 * =============================================================================
33 public Object vector_at (int i) {
34 if ((i < 0) || (i >= size)) {
35 System.out.println("Illegal Vector.element\n");
42 /* =============================================================================
44 * -- Returns false if fail, else true
45 * =============================================================================
47 public boolean vector_pushBack (Object dataPtr) {
48 if (size == capacity) {
49 int newCapacity = capacity * 2;
50 Object[] newElements = new Object[newCapacity];
52 //void** newElements = (void**)malloc(newCapacity * sizeof(void*));
53 if (newElements == null) {
56 capacity = newCapacity;
57 for (int i = 0; i < size; i++) {
58 newElements[i] = elements[i];
61 elements = newElements;
64 elements[size++] = dataPtr;
69 /* =============================================================================
71 * -- Returns null if fail, else returns last element
72 * =============================================================================
81 return (elements[--(size)]);
84 /* =============================================================================
86 * =============================================================================
94 /* =============================================================================
96 * =============================================================================
104 /* =============================================================================
106 * =============================================================================
111 //qsort.sort(elements, 0, (elements.length - 1));
112 qsort.sort(elements);
113 //qsort(elements, size, 4, compare);
116 * =============================================================================
118 * =============================================================================
120 public static boolean
121 vector_copy (Vector_t dstVectorPtr, Vector_t srcVectorPtr)
123 int dstCapacity = dstVectorPtr.capacity;
124 int srcSize = srcVectorPtr.size;
125 if (dstCapacity < srcSize) {
126 int srcCapacity = srcVectorPtr.capacity;
127 Object[] elements = new Object[srcCapacity];
129 if (elements == null) {
132 dstVectorPtr.elements = null;
133 dstVectorPtr.elements = elements;
134 dstVectorPtr.capacity = srcCapacity;
137 for(int i = 0; i< srcSize; i++) {
138 dstVectorPtr.elements[i] = srcVectorPtr.elements[i];
141 dstVectorPtr.size = srcSize;