Last active
August 29, 2015 13:56
-
-
Save bshlgrs/8799115 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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