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

ما معنى resize في ال array

مغلق
بدأه fahad611 في 30 مارس 2006 · 5 رد · 1,575 مشاهدة · في الأسئلة المجابة
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

أحلى تحية لأحلى فريق

ابدخل بالموضوع طوالي

في آخر محاضرة درست ترتيب الأرقام باستخدام the bubble sort

وطلب منا الدكتور حل آخر باستخدام دالة ترتيب الجدول resize

وقبل ذلك اقوم بحجز ديناميكي للجدول الذي نستخدم فيه الدالة resize

ودي اعرف ما معنى حجز ديناميكي لجدول و ما وظيفة الدالة resize

علما أني أثناء بحثي بالنت وجدت برنامج ما أدري هل يفي بالغرض

علما أن المطلوب هو ترتيب عدة أرقام مدخله تصاعديا باستخدام resize

وهذ البرنامج

#include <iostream.h>

#include<vector>

using namespace std;

//----------------------------------

class ArrayBub

{

private:

vector<double>v;

int nElems;

//----------------------------------

void swap(int one,int two)

{

double temp=v[one];

v[one]=v[two];

v[two]=temp;

}

//----------------------------------

public:

//----------------------------------

ArrayBub(int max):nElems(0)

{

v.resize(max);

}

//----------------------------------

void insert()

{

double value;

for(;;)

{

cout<<"Enter the number ,when you finished press zero :";

cin>>value;

if (value ==0)

break;

v[nElems]=value;

nElems++;

}

}

//----------------------------------

void display()

{

for (int j=0;j<nElems;j++)

cout<<v[j]<<" ";

cout<<endl;

}

//---------------------------------

void bubbleSort()

{

int out,in;

for(out=nElems-1;out>1;out--)

for(in=0;in<out;in++)

if(v[in]>v[in+1])

swap(in,in+1);

}

//---------------------------------

};

////////////////////////////////////

int main()

{

int maxSize=100;

ArrayBub arr(maxSize);

arr.insert();

arr.display();

arr.bubbleSort();

arr.display();

return 0;

}

ما وظيفة البرنامج

معليش يمكن فيه أخطاء بس تحملوني جديد على اللغة

مع خالص تحياتي

#2

آسف لم أكن اعرف طريقة كتابة الأكواد

bubbleSort


#include <iostream.h>
#include<vector>
using namespace std;
//----------------------------------
class ArrayBub
{
private:
vector<double>v;
int nElems;
//----------------------------------
void swap(int one,int two)
{
double temp=v[one];
v[one]=v[two];
v[two]=temp;
}
//----------------------------------
public:
//----------------------------------
ArrayBub(int max):nElems(0)
{
v.resize(max);
}
//----------------------------------
void insert()
{
double value;
for(;;)
{
cout<<"Enter the number ,when you finished press zero :";
cin>>value;
if (value ==0)
break;
v[nElems]=value;
nElems++;
}
}
//----------------------------------
void display()
{
for (int j=0;j<nElems;j++)
cout<<v[j]<<" ";
cout<<endl;
}
//---------------------------------
void bubbleSort()
{
int out,in;
for(out=nElems-1;out>1;out--)
for(in=0;in<out;in++)
if(v[in]>v[in+1])
swap(in,in+1);
}
//---------------------------------
};
////////////////////////////////////
int main()
{
int maxSize=100;
ArrayBub arr(maxSize);
arr.insert();
arr.display();
arr.bubbleSort();
arr.display();
return 0;
}
#3
اقتباس
معنى حجز ديناميكي لجدول

معناها أن المستخدم يحدد طول الvecotr فى مرحلة الruntime ولكن انتا فى الكود عامل initial للmaxvalue وبالتالى علشان تجعل الحجز ديناميكى خد القيمة الmaxvalue من المستخدم

أما عن الدالة resize() فدة شرحها من الhelp

void

resize (size_type sz, T c = T());

Alters the size of self. If the new size (sz) is greater than the current size, then sz-size() c's are inserted at the end of the vector. If the new size is smaller than the current capacity, then the vector is truncated by erasing size()-sz elements off the end. If sz is equal to capacity then no action is taken.

size_type

Rogue Wave Standard C++ Library User's Guide and Tutorial

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#4

تشكر أخي eng_3llam على ردك

لكن سؤالي ماوظيفة الكود السابق

هل نستطيع القول انه برنامج فرز مجموعة من الأرقام وترتيبها تصاعديا

#5
اقتباس
لكن سؤالي ماوظيفة الكود السابق

هل نستطيع القول انه برنامج فرز مجموعة من الأرقام وترتيبها تصاعديا هة جاوبت على نفسك :^)

Muhammad Allam

Computer Science

@Resource(MappedURL="My Blog" )

#6

ألف ألف شكر لك أستاذ eng_3llam

و إلى الأمام دوما

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

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