| 1 |
bearsoft |
1.1 |
#include "../Sort/ArrayQuickSort.h"
|
| 2 |
|
|
#include "../Binary/BinaryTools.h"
|
| 3 |
|
|
#include "IntArray.h"
|
| 4 |
|
|
#include "../System/SystemDefine.h"
|
| 5 |
|
|
|
| 6 |
|
|
IntArray::IntArray()
|
| 7 |
|
|
{
|
| 8 |
|
|
buffer=0;
|
| 9 |
|
|
size=0;
|
| 10 |
|
|
internIndex=0;
|
| 11 |
|
|
clearBuffer(0);
|
| 12 |
|
|
}
|
| 13 |
|
|
|
| 14 |
|
|
IntArray::IntArray(int iSize)
|
| 15 |
|
|
{
|
| 16 |
|
|
buffer=(int*)malloc(sizeof(int)*iSize);
|
| 17 |
|
|
size=iSize;
|
| 18 |
|
|
internIndex=0;
|
| 19 |
|
|
clearBuffer(0);
|
| 20 |
|
|
}
|
| 21 |
|
|
|
| 22 |
|
|
IntArray::~IntArray()
|
| 23 |
|
|
{
|
| 24 |
|
|
if (buffer!=0)
|
| 25 |
|
|
{
|
| 26 |
|
|
free(buffer);
|
| 27 |
|
|
}
|
| 28 |
|
|
}
|
| 29 |
|
|
|
| 30 |
|
|
void IntArray::clearBuffer(int clearValue)
|
| 31 |
|
|
{
|
| 32 |
|
|
for ( int i=0; i<size ; i++ )
|
| 33 |
|
|
{
|
| 34 |
|
|
buffer[i]=clearValue;
|
| 35 |
|
|
}
|
| 36 |
|
|
}
|
| 37 |
|
|
|
| 38 |
|
|
void IntArray::resetInternIndex()
|
| 39 |
|
|
{
|
| 40 |
|
|
internIndex=0;
|
| 41 |
|
|
}
|
| 42 |
|
|
|
| 43 |
|
|
void IntArray::internIndexForward()
|
| 44 |
|
|
{
|
| 45 |
|
|
if (internIndex >= 0 && (internIndex+1) < size )
|
| 46 |
|
|
{
|
| 47 |
|
|
internIndex++;
|
| 48 |
|
|
}
|
| 49 |
|
|
}
|
| 50 |
|
|
|
| 51 |
|
|
int IntArray::getInternIndex()
|
| 52 |
|
|
{
|
| 53 |
|
|
return internIndex;
|
| 54 |
|
|
}
|
| 55 |
|
|
|
| 56 |
|
|
void IntArray::sortLargestOrder()
|
| 57 |
|
|
{
|
| 58 |
|
|
ArrayQuickSort::setStatement(0);
|
| 59 |
|
|
ArrayQuickSort::sortLargestOrder(buffer,0,size-1);
|
| 60 |
|
|
}
|
| 61 |
|
|
|
| 62 |
|
|
void IntArray::sortSmallestOrder()
|
| 63 |
|
|
{
|
| 64 |
|
|
ArrayQuickSort::setStatement(1);
|
| 65 |
|
|
ArrayQuickSort::sortSmallestOrder(buffer,0,size-1);
|
| 66 |
|
|
}
|
| 67 |
|
|
|
| 68 |
|
|
void IntArray::setInt(int value,int index)
|
| 69 |
|
|
{
|
| 70 |
|
|
if (index >= 0 && index < size )
|
| 71 |
|
|
{
|
| 72 |
|
|
buffer[index]=value;
|
| 73 |
|
|
}
|
| 74 |
|
|
}
|
| 75 |
|
|
|
| 76 |
|
|
void IntArray::setInt(int value)
|
| 77 |
|
|
{
|
| 78 |
|
|
if (internIndex >= 0 && internIndex < size )
|
| 79 |
|
|
{
|
| 80 |
|
|
buffer[internIndex]=value;
|
| 81 |
|
|
}
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
void IntArray::removeInt(int index)
|
| 85 |
|
|
{
|
| 86 |
|
|
if (index >= 0 && index < size )
|
| 87 |
|
|
{
|
| 88 |
|
|
--size;
|
| 89 |
|
|
|
| 90 |
|
|
if (size > 0)
|
| 91 |
|
|
{
|
| 92 |
|
|
for ( int i=0; i<size ; i++ )
|
| 93 |
|
|
{
|
| 94 |
|
|
if ( i >= index )
|
| 95 |
|
|
{
|
| 96 |
|
|
buffer[i]=buffer[i+1];
|
| 97 |
|
|
}
|
| 98 |
|
|
}
|
| 99 |
|
|
}
|
| 100 |
|
|
}
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
int IntArray::getInt()
|
| 104 |
|
|
{
|
| 105 |
|
|
if (internIndex >= 0 && internIndex < size )
|
| 106 |
|
|
{
|
| 107 |
|
|
return buffer[internIndex];
|
| 108 |
|
|
}
|
| 109 |
|
|
|
| 110 |
|
|
return 0;
|
| 111 |
|
|
}
|
| 112 |
|
|
|
| 113 |
|
|
int IntArray::getInt(int index)
|
| 114 |
|
|
{
|
| 115 |
|
|
if (index >= 0 && index < size )
|
| 116 |
|
|
{
|
| 117 |
|
|
return buffer[index];
|
| 118 |
|
|
}
|
| 119 |
|
|
|
| 120 |
|
|
return 0;
|
| 121 |
|
|
}
|
| 122 |
|
|
|
| 123 |
|
|
void IntArray::addLast(int value)
|
| 124 |
|
|
{
|
| 125 |
|
|
BinaryTools binaryTools;
|
| 126 |
|
|
|
| 127 |
|
|
if (buffer==0)
|
| 128 |
|
|
{
|
| 129 |
|
|
buffer=(int*)malloc(sizeof(int)*1);
|
| 130 |
|
|
buffer[0]=value;
|
| 131 |
|
|
size=1;
|
| 132 |
|
|
}
|
| 133 |
|
|
else
|
| 134 |
|
|
{
|
| 135 |
|
|
int *tempBuffer=binaryTools.addIntValueToArray(buffer,size,value);
|
| 136 |
|
|
free(buffer);
|
| 137 |
|
|
buffer=tempBuffer;
|
| 138 |
|
|
size++;
|
| 139 |
|
|
}
|
| 140 |
|
|
}
|
| 141 |
|
|
|