this is a part of my code, d->ReadData() is the function which reads in the number. d is of class DATA, which i declare
Code:
do {
d->ReadData();
if (!d->v.empty()) {
if (d->v.size()+tranTol >= (unsigned int)support) {
arr = NewArray_db(d->v.size() + 1); // +1 to store the transaction number too
sort( d->v.begin(), d->v.end() );
arr[0] = d->v.size();
j=1;
for (unsigned int i=0; i<d->v.size(); i++) {
arr[j++] = d->v.at(i);
bucket_item[d->v.at(i)]++;
//cout << d->v[i] <<" ";
}
//cout <<endl;
}
else {
arr = NewArray_db(1);
arr[0] = 0;
}
tempt[index++] = arr;
for (int z=0; z<d->v.size(); z++) {
d->v[z] = 0;
}
d->v.clear();
d->v.resize(0);
}
else { //the transaction read in is empty
arr = NewArray_db(1);
arr[0] = 0;
tempt[index++] = arr;
d->v.clear();
}
} while (!feof(d->in));
Code:
void Data::ReadData() {
do {
usi pos=0, item=0;
c = getc(in);
if (c=='-') {//if read in a -1, skip it
c = getc(in);
c = getc(in);
}
while((c >= '0') && (c <= '9')) {
item *=10;
item += usi(c)-usi('0');
c = getc(in);
pos++;
}
if (pos) {
v.push_back(item); // add item to end of vector
}
if (c == '\n')
return;
} while (!feof(in));
}