System::Collections::Generic::Stack فئة

Stack class

Stack class forward declaration.

template<typename T>class Stack : public System::Collections::Generic::IEnumerable<T>
معاملالوصف
Tنوع العنصر.

Nested classes

الطرق

طريقةالوصف
AddRange(IEnumerablePtr)يضع العناصر في المكدس.
virtual Clear()يحذف جميع العناصر من المكدس.
virtual Contains(const T&) constيتحقق مما إذا كان العنصر المحدد موجودًا في الحاوية؛ يستخدم العامل == للمقارنة.
data()مُستَخدِم بنية البيانات الداخلية.
data() constمُستَخدِم بنية البيانات الداخلية.
virtual get_Count() constيحصل على عدد العناصر في المكدس.
GetEnumerator() overrideيحصل على المُعدِّد للتنقل عبر المكدس الحالي.
Peek()يحصل على العنصر من قمة المكدس، لكنه يبقى في المكدس.
Pop()يحصل على العنصر من أعلى المكدس.
Push(const T&)يضع عنصرًا في أعلى المكدس.
Stack()يبني مكدسًا فارغًا.
Stack(int)يبني مكدسًا فارغًا.
Stack(IEnumerablePtr)منشئ النسخ.
virtual ToArray()يحوّل المكدس إلى مصفوفة.
virtualizeBeginConstIterator() const overrideيحصل على تنفيذ begin const iterator للحاوية الحالية.
virtualizeBeginIterator() overrideيحصل على تنفيذ begin iterator للحاوية الحالية.
virtualizeEndConstIterator() const overrideيحصل على تنفيذ end const iterator للحاوية الحالية.
virtualizeEndIterator() overrideيحصل على تنفيذ end iterator للحاوية الحالية.

Typedefs

تعريف نوعالوصف
IEnumerablePtrمجموعة تحتوي على عناصر من نفس النوع.
IEnumeratorPtrEnumerator نوع.
stack_tمعلومات RTTI.
ValueTypeنوع القيمة.

ملاحظات

Stack class wrapping std::list. Objects of this class should only be allocated using System::MakeObject() function. Never create instance of this type on stack or using operator new, as it will result in runtime errors and/or assertion faults. Always wrap this class into System::SmartPtr pointer and use this pointer to pass it to functions as argument.

#include <system/collections/stack.h>
#include <system/smart_ptr.h>

using namespace System;
using namespace System::Collections::Generic;

void PrintItems(const SmartPtr<IEnumerable<int>> &stack)
{
  for (const auto item: stack)
  {
    std::cout << item << ' ';
  }
  std::cout << std::endl;
}

int main()
{
  // أنشئ نسخة من فئة Stack.
  auto stack = MakeObject<Stack<int>>();

  // املأ المكدس.
  stack->Push(1);
  stack->Push(2);
  stack->Push(3);

  // اطبع العنصر الأخير من المكدس. طريقة Peek لا تُزيل العنصر من المكدس.
  std::cout << stack->Peek() << std::endl;
  PrintItems(stack);

  // اطبع العنصر الأخير من المكدس. طريقة Pop تُزيل العنصر من المكدس.
  std::cout << stack->Pop() << std::endl;
  PrintItems(stack);

  return 0;
}
/*
This code example produces the following output:
3
3 2 1
3
2 1
*/

انظر أيضًا