C / C++ Code Portfolio


void pop(); // Remove front element from queue T &front(); // Return ref to front element in queue const



Download 112,15 Kb.
bet28/30
Sana01.03.2022
Hajmi112,15 Kb.
#475852
1   ...   22   23   24   25   26   27   28   29   30
Bog'liq
dddd

void pop(); // Remove front element from queue
T &front(); // Return ref to front element in queue
const T &front() const; // Return const ref to front element in queue
bool empty() const; // Return whether queue is empty
size_t size() const; // vused_ accessor

private:
T* v_; // Elements in queue
size_t vsize_; // Max number of elements in queue
size_t vused_; // Number of elements in queue
};


template<typename T>
Queue::Queue() : v_(static_cast(operator new(sizeof(T) * initialSize))), vsize_(initialSize), vused_(0)
{ }

template<typename T>
Queue::~Queue()
{
destroy(v_, v_ + vused_);
operator delete(v_);
}

// Helper function for the copy constructor, performs the copy


template<typename T>
T* newCopy(const T *src, size_t srcsize, size_t destsize)
{
// Ensure enough memory will be allocated in the destination
assert(destsize >= srcsize);
// Allocate memory for the destination copy
T* dest = new T[destsize];
try
{
// Perform the copy
copy(src, src + srcsize, dest);
}
catch (...)
{
// If there was a problem, free destination memory
delete[] dest;
throw;
}
return dest;
}

// Copy constructor


template<typename T>
Queue::Queue(const Queue &other)
: v_(newCopy(other.v_, other.vsize_, other.vsize_)), vsize_(other.vsize_), vused_(other.vused_)
{ }

// Copy assignment operator


template<typename T>
Queue& Queue::operator=(const Queue &other)
{
// if the two variables of the assignment aren't already equal, perform the assignment
if (this != &other)
{
// Create a new copy of the RHS variable
T* v_new = newCopy(other.v_, other.vsize_, other.vsize_);
// Clear the LHS variable buffer
delete[] v_;
// Make the LHS variable data members equal to the RHS variable data members
v_ = v_new;
vsize_ = other.vsize_;
vused_ = other.vused_;
}

Download 112,15 Kb.

Do'stlaringiz bilan baham:
1   ...   22   23   24   25   26   27   28   29   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish