C / C++ Code Portfolio



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

template <typename T1, typename T2>
void construct(T1 *p, const T2 &value)
{
new (p) T1(value);
}

// Destroy an object (but does not deallocate any memory)


template <typename T>
void destroy(T *p)
{
p->~T();
}

// Destroy an object range (but does not deallocate any memory)


template <typename FwdIter>
void destroy(FwdIter first, FwdIter last)
{
while (first != last)
{
destroy(&*first);
++first;
}
}

// Exchange the values of two objects


template <typename T>
void swap(T &a, T &b)
{
T temp(a);
a = b;
b = temp;
}

// Return first element in queue


template<typename T>
T & Queue::front()
{
// if the queue is empty, throw an exception and report to user
if (vused_ == 0)
{
throw logic_error("Error: empty queue");
}
// otherwise, return the first element in the queue
else
{
return v_[0];
}
}

// Return first element in queue


template<typename T>
const T & Queue::front() const
{
// if the queue is empty, throw an exception and report to user
if (vused_ == 0)
{
throw logic_error("Error: empty queue");
}
// otherwise, return the first element in the queue
else
{
return v_;
}
}

// Determine whether queue is empty


template<typename T>
bool Queue::empty() const
{
return (vused_ == 0);
}

// vused_ accessor


template<typename T>
size_t Queue::size() const
{
return vused_;
}

int main()
{
Queue myQueue;
cout << "Is the queue empty? Answer: " << myQueue.empty() << "\n";
for (int i = 0; i < numElems; ++i)
{
cout << "Pushing " << elems[i] << " to queue\n";
myQueue.push(elems[i]);
}
cout << "Is the queue empty? Answer: " << myQueue.empty() << "\n";
cout << "The current front element is " << myQueue.front() << " and the current size is " << myQueue.size() << "\n";
for (int i = 0; i < numElems-1; ++i)
{
cout << "Popping " << myQueue.front() << ". ";
myQueue.pop();
cout << "The current front element is " << myQueue.front() << " and the current size is " << myQueue.size() << "\n";
}
Queue myQueue2;
for (int i = 0; i < numElems; ++i)
{
cout << "Pushing " << elems[i] << " to queue 2\n";
myQueue2.push(elems[i]);
}
Queue myQueue3;
myQueue3 = myQueue2;
cout << "Queue 3 front: " << myQueue3.front() << ", queue 2 front: " << myQueue2.front() << "\n";
cout << "Queue 3 size: " << myQueue3.size() << ", queue 2 size: " << myQueue2.size() << "\n";
}
©2022 Christopher George Berger · All Rights Reserved · License · About · Linked

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