Get element count for a Stack : Stack « Collections « Visual C++ .NET






Get element count for a Stack

 
#include "stdafx.h"
using namespace System;
using namespace System::Collections;

void main()
{
    Queue ^que = gcnew Queue();
    Stack ^stk = gcnew Stack();

    array<String^>^ entry = gcnew array<String^> { "First", "Second", "Third", "Fourth" };

    for (int i = 0; i < entry->Length; i++)
    {
        que->Enqueue(entry[i]);
        stk->Push(entry[i]);  

        Console::WriteLine("{0}\t\t{1}", entry[i], entry[i]);
    }
    while ((que->Count > 0) && (stk->Count > 0))
    {
        Console::WriteLine("{0}\t\t{1}", que->Dequeue(), stk->Pop());
    }

    que->Clear();
    stk->Clear();
}

   
  








Related examples in the same category

1.Push value to a Stack
2.Call Pop method to remove element from a Stack
3.Push value to stack
4.Pop pets from stack top till empty