C / C++ Code Portfolio



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

return *this;
}

// Push a new value to the back of the queue


template<typename T>
void Queue::push(const T &t)
{
// If the queue is out of space, allocate new space for more queue items
if (vused_ == vsize_)
{
// double the size of the new queue
size_t vsize_new = vsize_ * 2 + 1;
cout << "Increasing size of Queue. Current size: " << vused_ << ", new size: " << vsize_new << "\n";
// allocate new memory for a larger queue, but do not construct any objects
T *v_new_safe = static_cast(operator new(vsize_new * sizeof(T)));
// construct each object for the new queue
for (size_t i = 0; i < vused_; ++i)
{
construct(v_new_safe + i, v_[i]);
}
// copy elements from the old small queue into the new large queue
swap(v_, v_new_safe);
// destroy the objects in the temporary queue
destroy(v_new_safe);
// deallocate memory from the temporary queue
operator delete(v_new_safe);
vsize_ = vsize_new;
}
// push the new value to the end of the queue
construct(v_ + vused_, t);
// increment number of items in the queue
++vused_;
}

// pop the front value from the queue


template<typename T>
void Queue::pop()
{
// if the queue is empty, cannot pop a value; throw
if (vused_ == 0)
{
throw logic_error("Error: attempt to pop from empty queue");
}
// otherwise, move all of the elements of the queue one closer to the front
// and decrement vused_
// I am guessing this is absurdly inefficient but it works
else
{
for (size_t element = 1; element <= vused_; ++element)
{
v_[element - 1] = v_[element];
}
--vused_;
}
}

// Constructs a new object in a given location using a given value



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