2
224419
Guest
i am getting this exception in the push function. can someone please help me with this?here is my code:
#include<iostream>
#include <ctime>
#define stack_size 1000000000
using namespace std;
class stack {
private:
long *data = new long[stack_size];
//delete[] data;
//long data[stack_size];
int top;
public:
stack();
void push(int item);
int pop();
};
stack::stack()
{
top = -1;
}
void stack:ush(int item) {
top++;
data[top] = item;
}
int stack:op() {
top--;
return data[top + 1];
}
int main() {
int start_s = clock();
int item;
//stack();
stack temp1;
//millions of operations
for (int i = -1; i < 1000000; i++) {
item = rand() % 1000 + 1;
temp1.push(item);
}
for (int i = 1000000; i < -1; i--) {
temp1.pop();
}
int stop_s = clock();
cout << "millions of operations for millions of values take: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << " milliseconds" << endl;
start_s = clock();
//billions of operations for 1000 elements
for (int i = 0; i < 1000000; i++)
{
for (int i = -1; i < 1000; i++) {
item = rand() % 100 + 1;
temp1.push(item);
}
}
for (int i = 0; i < 1000000; i++)
{
for (int i = 1000; i < -1; i--) {
temp1.pop();
}
}
stop_s = clock();
cout << "billions of operations takes: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << " milliseconds" << endl;
system("PAUSE");
}
Continue reading...
#include<iostream>
#include <ctime>
#define stack_size 1000000000
using namespace std;
class stack {
private:
long *data = new long[stack_size];
//delete[] data;
//long data[stack_size];
int top;
public:
stack();
void push(int item);
int pop();
};
stack::stack()
{
top = -1;
}
void stack:ush(int item) {
top++;
data[top] = item;
}
int stack:op() {
top--;
return data[top + 1];
}
int main() {
int start_s = clock();
int item;
//stack();
stack temp1;
//millions of operations
for (int i = -1; i < 1000000; i++) {
item = rand() % 1000 + 1;
temp1.push(item);
}
for (int i = 1000000; i < -1; i--) {
temp1.pop();
}
int stop_s = clock();
cout << "millions of operations for millions of values take: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << " milliseconds" << endl;
start_s = clock();
//billions of operations for 1000 elements
for (int i = 0; i < 1000000; i++)
{
for (int i = -1; i < 1000; i++) {
item = rand() % 100 + 1;
temp1.push(item);
}
}
for (int i = 0; i < 1000000; i++)
{
for (int i = 1000; i < -1; i--) {
temp1.pop();
}
}
stop_s = clock();
cout << "billions of operations takes: " << (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 << " milliseconds" << endl;
system("PAUSE");
}
Continue reading...