#include <iostream> #include <cstdlib> #include <assert.h> #include "ia.h" int& i_arr::operator [] (const unsigned int index) { class i_arr *ptrc; unsigned int i; ptrc = this; i = index; while (i >= BSIZE) { if (ptrc->next == NULL) { ptrc->next = new i_arr; if (ptrc->next == NULL) { std::cerr << "Error:Out of memory\n"; exit(8); } } ptrc = ptrc->next; i -= BSIZE; } assert(i >= 0); assert(i < sizeof(ptrc->data)/sizeof(ptrc->data[0])); return (ptrc->data[i]); } i_arr::~i_arr( ) { if (next != NULL) { delete next; next = NULL; } }
Sunday, 29 April 2012
C++ Program to implement Infinite Arrays
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment