?
=?iso-8859-9?B?RGlu52F5IEFr5/ZyZW4=?=
Following function
void mdelr(int *ar1, int a, int b, int d )
{
int i,j,tmp;
int *temp;
for (i=0; i<a; i++)
{
for(j=0; j<b; j++)
{
if (i >= d)
ar1[i*b+j] = ar1[(i+1)*b+j];
if (i == b-1)
ar1[i*b+j] = 0;
}
}
tmp = ar1[0];
temp = new int[(a-1)*b];
for(i=0; i<b*a-b; i++)
temp = ar1;
delete ar1;
ar1 = temp;
cout << "\last version of array" << d << " " << tmp << "\n";
for (i=0; i<a-1; i++)
{
for(j=0; j<b; j++)
{
cout << ar1[i*b +j] << " ";
}
cout << "\n";
}
}
and following main block
int main(void)
{
int *ar1,*ar2;
int i,j,k;
int temp, sayi,ROW,COL;
int *pt;
ROW=COL=5;
ar1 = new int[ROW*COL];
cout << "row number to be deleted";
cin >> sayi;
pt = new int[sayi];
for(i=0; i<sayi; i++)
{
cout << "Enter col num" << i;
cin >> temp;
temp--;
pt = temp-i;
}
for(i=0; i<sayi; i++)
cout << pt << " ";
cout << "\n";
system("pause");
/*assign values*/
for (i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
{
ar1[i*COL +j] = (i+i+j+1);
}
}
cout << "original matrix\n";
for (i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
{
cout << ar1[i*ROW +j] << " ";
}
cout << "\n";
}
for(k=0; k<sayi; k++)
{
cout << "step " << k << "\n";
mdelr(ar1,ROW-k,COL,pt[k]);
cout << "\nresult in main" << k << "\n";
for (i=0; i<ROW-k-1; i++)
{
for(j=0; j<COL; j++)
{
cout << ar1[i*(COL) +j] << " ";
}
cout << "\n";
}
}
delete ar1;
delete pt;
system("pause");
return 0;
}
gives the following output
row number to be deleted 2
Enter col num02
Enter col num14
1 2
Devam etmek için bir tusa basýn . . .
original matris
1 2 3 4 5
3 4 5 6 7
5 6 7 8 9
7 8 9 10 11
9 10 11 12 13
step 0
last version of array1 1
1 2 3 4 5
5 6 7 8 9
7 8 9 10 11
9 10 11 12 13
result in main 0
0 2 3 4 5
5 6 7 8 9
7 8 9 10 11
9 10 11 12 13
adim 1
last version of array2 0
0 2 3 4 5
5 6 7 8 9
9 10 11 12 13
result in main 1
4007120 2 3 4 5
5 6 7 8 9
9 10 11 12 13
Devam etmek için bir tusa basýn . . .
My question is why the first element of the array becomes stupid
despite all of my effords? I believe returning to main changes the
first element but I cannot prevent this.
void mdelr(int *ar1, int a, int b, int d )
{
int i,j,tmp;
int *temp;
for (i=0; i<a; i++)
{
for(j=0; j<b; j++)
{
if (i >= d)
ar1[i*b+j] = ar1[(i+1)*b+j];
if (i == b-1)
ar1[i*b+j] = 0;
}
}
tmp = ar1[0];
temp = new int[(a-1)*b];
for(i=0; i<b*a-b; i++)
temp = ar1;
delete ar1;
ar1 = temp;
cout << "\last version of array" << d << " " << tmp << "\n";
for (i=0; i<a-1; i++)
{
for(j=0; j<b; j++)
{
cout << ar1[i*b +j] << " ";
}
cout << "\n";
}
}
and following main block
int main(void)
{
int *ar1,*ar2;
int i,j,k;
int temp, sayi,ROW,COL;
int *pt;
ROW=COL=5;
ar1 = new int[ROW*COL];
cout << "row number to be deleted";
cin >> sayi;
pt = new int[sayi];
for(i=0; i<sayi; i++)
{
cout << "Enter col num" << i;
cin >> temp;
temp--;
pt = temp-i;
}
for(i=0; i<sayi; i++)
cout << pt << " ";
cout << "\n";
system("pause");
/*assign values*/
for (i=0;i<ROW;i++)
{
for(j=0;j<COL;j++)
{
ar1[i*COL +j] = (i+i+j+1);
}
}
cout << "original matrix\n";
for (i=0; i<ROW; i++)
{
for(j=0; j<COL; j++)
{
cout << ar1[i*ROW +j] << " ";
}
cout << "\n";
}
for(k=0; k<sayi; k++)
{
cout << "step " << k << "\n";
mdelr(ar1,ROW-k,COL,pt[k]);
cout << "\nresult in main" << k << "\n";
for (i=0; i<ROW-k-1; i++)
{
for(j=0; j<COL; j++)
{
cout << ar1[i*(COL) +j] << " ";
}
cout << "\n";
}
}
delete ar1;
delete pt;
system("pause");
return 0;
}
gives the following output
row number to be deleted 2
Enter col num02
Enter col num14
1 2
Devam etmek için bir tusa basýn . . .
original matris
1 2 3 4 5
3 4 5 6 7
5 6 7 8 9
7 8 9 10 11
9 10 11 12 13
step 0
last version of array1 1
1 2 3 4 5
5 6 7 8 9
7 8 9 10 11
9 10 11 12 13
result in main 0
0 2 3 4 5
5 6 7 8 9
7 8 9 10 11
9 10 11 12 13
adim 1
last version of array2 0
0 2 3 4 5
5 6 7 8 9
9 10 11 12 13
result in main 1
4007120 2 3 4 5
5 6 7 8 9
9 10 11 12 13
Devam etmek için bir tusa basýn . . .
My question is why the first element of the array becomes stupid
despite all of my effords? I believe returning to main changes the
first element but I cannot prevent this.