Hello everyone,
I am trying to manipulate "DYNAMIC ARRAY" Structures however I've been faced with problems wanting adding new value. Here my code:: -I use CodeBlocks and gnu gcc compiler ^ also I checked it on linux machine.
#include <iostream>
using namespace std;
#include "Deneme.h"
Deneme::Deneme()
{
countReg = 0;
pArray = new int[(countReg+1)];
for (int i = 0; i < countReg+1; i++)
{
pArray[i] = NULL;
cout<<pArray[i]<<"\t";
}
cout<<endl;
cout<<"CONSTRUCTOR: "<<endl;
}
Deneme::~Deneme()
{
cout<<"DESTRUCTOR: "<<endl;
delete [] pArray;
}
void Deneme::insertEl(int id)
{
cout<<"Element "<<id<<" has been added "<<endl;
pArray[countReg] = id;
/** display */
for (int j = 0; j < countReg+1; ++j)
cout<<pArray[j]<<"\t";
cout<<endl;
cout<<endl;
/** end display */
int* tempArray;
tempArray = new int[(countReg+1)];
for (int j = 0; j < countReg+1; ++j)
{
tempArray[j] = pArray[j];
cout<<tempArray[j]<<"\t";
}
cout<<endl;
delete [] pArray;
pArray = tempArray;
countReg++;
}
int main()
{
Deneme D;
D.insertEl(207);
D.insertEl(98);
D.insertEl(87);
D.insertEl(112);
D.insertEl(122);
return 0;
}
I tried another version that pArray = NULL in Constructor ^ pArray = new int[countReg+1]; in insertEL function but at this time I can not keep before adding data, pls help I am working on this homework for many hours but I could not manage to throw integer || objects- later work- datas pArray pointer-dynamic array, thank u for ur help...