الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

help with resizing an array

مغلق
بدأه manayer88 في 17 يونيو 2002 · 0 رد · 204 مشاهدة · في ارشيف قسم C/C++
مشاركة: واتساب X فيسبوك تيليجرام
#1

salam 3alekom

i really need help with this, anyone please ASAP. i am waiting. thanks so much,,,,by the way this is my firtst time here.

The SetBase member function of the Array class defined in Program simply changes the value of the base member variable. As a result, after the base is changed, all the array elements appear to have moved. How might the routine be modified so that the elements of the array don't change their apparent locations when the base is changed?

//

// This file contains the C++ code from Program 4.8 of

// "Data Structures and Algorithms

// with Object-Oriented Design Patterns in C++"

// by Bruno R. Preiss.

//

//

template

void Array::SetBase (unsigned int newBase)

{ base = newBase; }

template

void Array::SetLength (unsigned int newLength)

{

T* const newData = new T [newLength];

unsigned int const min =

length < newLength ? length : newLength;

for (unsigned int i = 0; i < min; ++i)

newData = data ;

delete [] data;

data = newData;

length = newLength;

}

هذا الموضوع مغلق.

مواضيع مشابهة