Skip to content

Instantly share code, notes, and snippets.

@bshlgrs
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bshlgrs/8799115 to your computer and use it in GitHub Desktop.
Save bshlgrs/8799115 to your computer and use it in GitHub Desktop.
#include <iostream>
class DynamicIntArray {
public:
DynamicIntArray() {
contents = new int[2];
capacity = 2;
current_usage = 0;
}
int capacity, current_usage;
int *contents;
void printArray();
void push(int x);
};
void DynamicIntArray::printArray() {
int i;
printf("here's your array: ");
for(i = 0; i < current_usage; i++) {
printf("%d, ", contents[i]);
}
printf("\ncapacity: %d. current_usage: %d\n\n", capacity, current_usage);
}
void DynamicIntArray::push(int x) {
contents[current_usage++] = x;
}
int main () {
DynamicIntArray x;
int y;
for (y=0; y<10000; y++) {
x.push(y);
}
x.printArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment