This is a Last In First Out Stack implementation using C++/CLI. The nodes are stored in a single-linked list..Code:#pragma once using namespace System; public ref class Stack { public: Stack() { first = nullptr; } property Boolean IsEmpty { Boolean get() { return (first == nullptr); } } property UInt32 Size { UInt32 get() { return (size); } } Object^ Pop() { if (first == nullptr) { throw gcnew Exception("Can't pop from an empty Stack."); } else { Object^ temp = (first->value); first = (first->next); size--; return (temp); } } void Push(Object^ o) { first = gcnew Node(o, first); size++; } void Clear() { first = nullptr; } ref struct Node { Node^ next; Object^ value; Node(Object^ o) { next = nullptr; value = o; } Node(Object^ o, Node^ n) { next = n; value = o; } }; private: Node^ first; UInt32 size; };
The Ultimate Guide Thread
Last edited by Dyndrilliac; Today at 06:10 PM.. Reason: Ended a sentence with a preposition.
There are currently 1 users browsing this thread. (0 members and 1 guests)